I am supposed to get an Image from a url and convert it into byte[]
. The following is what I achieved
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("http://xamarin.com/content/images/pages/forms/example-app.png"));
but now I am unable to convert the Image type to byte[]
.
Is this the correct way to approach? Any kind of help would be appreciated.
FFImageLoading (https://github.com/molinch/FFImageLoading/)
CachedImage
hasGetImageAsJPG
andGetImageAsPNG
methods. It's a direct Xamarin.FormsImage
class replacement with a lot of additional features.Here's the code used for image retrieving (it can be used in a
Image
class custom renderers):I haven't tried this but from my initial thought you will need a Stream. For that you could use
StreamImageSource
From there you can use the code from this.
Xamarin.Forms inside it uses
IImageSourceHandler
which has realizations likeImageLoaderSourceHandler
- for UriImageSourceStreamImagesourceHandler
- for StreamImageSourceFor reading data from
UriImageSource
You should useImageLoaderSourceHandler
which is platform class. So under each platform use code likeThen you can reach any data from UIImage under iOS or from Bitmap under Android. There are a lot of tutorials how to get byte[] from them.
It's posible to use WebClient to obtain byte array from a URL.