public void UnlockBits(BitmapData data) { if ((ImageLockMode)data.Reserved == ImageLockMode.ReadOnly) { return; } if (NativeCGImage.BitsPerPixel == 32) { if (!ConversionHelpers.sTablesInitialized) { ConversionHelpers.CalculateTables(); } Convert_BGRA_8888_To_P_RGBA_8888(bitmapBlock, data.Stride * data.Height); } }
public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat pixelFormat) { // We don't support conversion if (PixelFormat != pixelFormat) { throw new ArgumentException("", "pixelFormat"); } if (rect != new RectangleF(new PointF(0, 0), physicalDimension)) { throw new NotImplementedException("Sub rectangles of bitmaps not supported yet."); } // Bitmap created from external data, convert it if (bitmapBlock == IntPtr.Zero) { GetRenderableContext(); } BitmapData bitmapData = new BitmapData(); //bitmapData.Scan0 = (IntPtr)((long)pinnedScanArray.AddrOfPinnedObject() + ((rect.Left * NativeCGImage.BitsPerPixel + 7) / 8) + (rect.Top * NativeCGImage.BytesPerRow)); bitmapData.Scan0 = bitmapBlock; bitmapData.Height = (int)rect.Height; bitmapData.Width = (int)rect.Width; bitmapData.PixelFormat = pixelFormat; bitmapData.Stride = (int)NativeCGImage.BytesPerRow; bitmapData.Reserved = (int)flags; if (flags != ImageLockMode.WriteOnly) { if (NativeCGImage.BitsPerPixel == 32) { if (!ConversionHelpers.sTablesInitialized) { ConversionHelpers.CalculateTables(); } Convert_P_RGBA_8888_To_BGRA_8888(bitmapBlock, bitmapData.Stride * bitmapData.Height); } } return(bitmapData); }