private void MakeSureWeHaveAnAlphaChannel()
{
// Initialize our prmultiplied tables.
if (!ConversionHelpers.sTablesInitialized)
ConversionHelpers.CalculateTables ();
var alphaInfo = NativeCGImage.AlphaInfo;
var hasAlpha = ((alphaInfo == CGImageAlphaInfo.PremultipliedLast)
|| (alphaInfo == CGImageAlphaInfo.PremultipliedFirst)
|| (alphaInfo == CGImageAlphaInfo.Last)
|| (alphaInfo == CGImageAlphaInfo.First) ? true : false);
if (cachedContext != null && cachedContext.Handle != IntPtr.Zero)
{
return;
}
// set our pixel format
pixelFormat = PixelFormat.Format32bppArgb;
// and mark the rawformat as from memory
rawFormat = ImageFormat.MemoryBmp;
//format = GetBestSupportedFormat (pixelFormat);
cachedContext = CreateCompatibleBitmapContext ((int)NativeCGImage.Width, (int)NativeCGImage.Height, pixelFormat);
// Fill our pixel data with the actual image information
cachedContext.DrawImage (new CGRect (0, 0, (int)NativeCGImage.Width, (int)NativeCGImage.Height), NativeCGImage);
// Dispose of the prevous image that is allocated.
NativeCGImage.Dispose ();
// Get a reference to the pixel data
bitmapBlock = cachedContext.Data;
int size = (int)(cachedContext.BytesPerRow * cachedContext.Height);
var provider = new CGDataProvider (cachedContext.Data, size, true);
// Get the image from the bitmap context.
//NativeCGImage = bitmapContext.ToImage ();
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
NativeCGImage = new CGImage ((int)cachedContext.Width, (int)cachedContext.Height, (int)cachedContext.BitsPerComponent,
(int)cachedContext.BitsPerPixel, (int)cachedContext.BytesPerRow,
colorSpace,
cachedContext.AlphaInfo,
provider, null, true, CGColorRenderingIntent.Default);
colorSpace.Dispose ();
}