unsafe byte GetByte(int offset, IntPtr buffer)
{
byte* bufferAsBytes = (byte*) buffer;
return bufferAsBytes[offset];
}
protected CGBitmapContext CreateARGBBitmapContext(CGImage inImage)
{
var pixelsWide = inImage.Width;
var pixelsHigh = inImage.Height;
var bitmapBytesPerRow = pixelsWide * 4;
var bitmapByteCount = bitmapBytesPerRow * pixelsHigh;
using(var colorSpace = CGColorSpace.CreateDeviceRGB())
{
var bitmapData = Marshal.AllocHGlobal(bitmapByteCount);
if(bitmapData == IntPtr.Zero)
{
throw new Exception("Memory not allocated.");
}
var context = new CGBitmapContext(bitmapData, pixelsWide, pixelsHigh, 8,
bitmapBytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedFirst);
if(context == null)
{
throw new Exception("Context not created");
}
return context;
}
}
protected IntPtr RequestImagePixelData(UIImage inImage)
{
imageSize = inImage.Size;
CGBitmapContext ctxt = CreateARGBBitmapContext(inImage.CGImage);
var rect = new RectangleF(0.0f, 0.0f, imageSize.Width, imageSize.Height);
ctxt.DrawImage(rect, inImage.CGImage);
var data = ctxt.Data;
return data;
}