anand
anand

Reputation: 1459

How to show byte array of image in gallery as image in xamarin.ios?

I am downloading an image from api. This api provides me the bytes of image. Now I want to show this image in gallery (like normal images that is available in gallery). Means when user click the button in app, it should download the image's byte array and the image should open in full screen in gallery.

Like this

enter image description here

Upvotes: 1

Views: 505

Answers (1)

Ax1le
Ax1le

Reputation: 6643

If you want to save this to system gallery. You can try to convert your byte array to UIImage, then save this image:

NSData data = NSData.FromStream(new MemoryStream(imageBytes));
// Or NSData data = NSData.FromArray(imageBytes);
UIImage img = UIImage.LoadFromData(data);
img.SaveToPhotosAlbum((image, error) =>
{

});

On iOS 11, if you want to add images to photo library, do not forget to add the NSPhotoLibraryAddUsageDescription key in info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Our application needs permission to write photos...</string>

Upvotes: 1

Related Questions