Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xamarin.forms get byte array from imagesource

I have svg xml that i can convert to ImageSource or FileImageSource by using XamSVG library in the PCL project of my xamarin.forms.

I want to convert the ImageSource / FileImageSource to byte array (to get the bitmap).

Is this possible ?

like image 212
asaf Avatar asked Dec 19 '22 16:12

asaf


2 Answers

ImageSource doesn't expose any mechanism to retrieve the original image source. Instead, you will need to manually keep a reference to the original source you use to create the image.

like image 92
Jason Avatar answered Jan 20 '23 01:01

Jason


found the solution !!!

        StreamImageSource streamImageSource  = (StreamImageSource) some image source...
        System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;
        Task<Stream> task = streamImageSource.Stream(cancellationToken);
        Stream stream = task.Result;
like image 35
asaf Avatar answered Jan 19 '23 23:01

asaf