0

How can I get the pixel data bytes from a Xamarin.IOS UIImage object or from a Xamarin.IOS UIImageView.Image ?

I want to get the pixel data bytes so I can write them to a file, and later use LoadFromData() to load the UIImage.

Doug Null
  • 7,989
  • 15
  • 69
  • 148
  • LoadFromData expects data in a supported image format (png, jpg, etc) not raw pixel data. Based on what you've posted before I think the best approach would be to save the image as a jpg on the windows side, before you stream it to iOS – Jason Jan 04 '19 at 01:24
  • Agreed, thanks. On the Windows side, I'm using UWP and so now I know how Alice in Wonderland felt. ;-) – Doug Null Jan 05 '19 at 01:22

1 Answers1

0

You can use this.

    using (NSData imageData = image.AsPNG()) {
  Byte[] myByteArray = new Byte[imageData.Length];
  System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
}

Source: Converting UIImage to Byte Array