title: How do I best convert raw pixel data to a PNG file?
body: <p>(I'm working on a Xamarin.Forms  project targeting iOS, but I get the feeling I need to use monotouch to accomplish my goals.)</p>
  
  <p>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 <code>System.Drawing.Bitmap</code>, then use the <code>Save()</code> method. In Xamarin for Android, <code>Android.Graphics.Bitmap</code> has a <code>Compress()</code> method that lets me output to a stream. I'm having trouble figuring out what the equivalent in Xamarin iOS would be.</p>
  
  <p>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 <code>CGImage</code> from that, currently via a <code>CGBitmapContext</code>. I can get a <code>UIImage</code> from that, but the next clear method is <code>UIImage.SaveToPhotoStream()</code> which isn't what I want to do. I see <code>AsPng()</code> returns an <code>NSData</code>, 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?</p>