(I'm working on a Xamarin.Forms project targeting iOS, but I get the feeling I need to use monotouch to accomplish my goals.)
I have an array I get from a function, and this array represents some bitmap data I would like to save and display later. I've been looking at the documentation, and I don't see a path from bytes to bitmap to file that is as clear as I'd expect. In WinForms, I'd create a System.Drawing.Bitmap
, then use the Save()
method. In Xamarin for Android, Android.Graphics.Bitmap
has a Compress()
method that lets me output to a stream. I'm having trouble figuring out what the equivalent in Xamarin iOS would be.
The pixel data is 32 bits per pixel, 8 bits per component, ARGB. I've got as far as figuring out I can create a CGImage
from that, currently via a CGBitmapContext
. I can get a UIImage
from that, but the next clear method is UIImage.SaveToPhotoStream()
which isn't what I want to do. I see AsPng()
returns an NSData
, and that seems like a way to go. I don't quite have it working yet (because for some reason the provider decided to output int[] instead of byte[]) but I'm curious: is there an easier way to go from raw pixel data to a PNG file?