public override object Decode( System.IO.Stream input, System.IO.Stream output, params object[] args )
{
ImageData data = new ImageData();
UIImage bitmap = null;
try
{
bitmap = UIImage.LoadFromData(NSData.FromStream(input));
data.height = bitmap.CGImage.Height;
data.width = bitmap.CGImage.Width;
data.depth = 1;
data.format = Convert( bitmap.CGImage.BitmapInfo );
data.numMipMaps = 0;
//int[] pixels = new int[ bitmap.Width * bitmap.Height ];
// Start writing from bottom row, to effectively flip it in Y-axis
//bitmap.CGImage.DataProvider.CopyData().Bytes GetPixels( pixels, pixels.Length - bitmap.Width, -bitmap.Width, 0, 0, bitmap.Width, bitmap.Height );
NSData tmpData = bitmap.CGImage.DataProvider.CopyData();
/*
IntPtr sourcePtr = tmpData.Bytes;
byte[] outputBytes = new byte[ data.width * data.height * Marshal.SizeOf( typeof( int ) ) ];
IntPtr destPtr = Memory.PinObject( outputBytes );
Memory.Copy( sourcePtr, destPtr, outputBytes.Length );
output.Write( outputBytes, 0, outputBytes.Length );
*/
byte[] outputBytes = tmpData.ToArray();
output.Write( outputBytes, 0, outputBytes.Length );
return data;
}
finally
{
if ( bitmap != null )
{
bitmap.Dispose();
}
}
}