Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ImageSource to Stream

$
0
0

Hey guys,

I am trying to persist a user photo by converting it to a byte array.
The initial placeholder image is loaded using xaml and static resources.
The holdup is, that ImageSource is a XF Element which doesn't seem to expose the Stream, but only stores the value for display.

This is how I am currently converting the Image to a byte array:

        private byte[] ImageRaw { get; set; }

        [Ignore]
        public MemoryStream Image
        {
            get { return new MemoryStream(ImageRaw); }
            set
            {
                ImageRaw = new byte[value.Length];
                value.Read(ImageRaw, 0, ImageRaw.Length);

                Persist();
            }
        }

Then I'll simple fetch the stream and use it for an ImageSource:
ImageSource.FromStream(() => Profile.Image);

Now, I am trying to figure out how to do it the other way around, something like this:

var stream = ImageSource.FromResource(ImageResources.DemoGirl).GET_THE_UNDERLYING_STREAM();
myUserProfile.Image = stream;

Does anyone know how to do this?
Or if it is possible at all.

Thanks in advance.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>