是否可以使用 BitBlt 直接从 GDI+ 位图中复制而不使用 GetHBitmap?
GetHBitmap 速度很慢,因为它除了 BitBlt 副本之外还创建整个图像的新副本,并且比 BitBlt 副本慢,并且必须释放给定的 HBITMAP。图片很大。
有没有办法让BitBlt使用原始GDI+图像的像素数据?
编辑:我可以获得指向 GDI+ 位图像素数据在内存中位置的指针。我可以创建一个指向 GDI+ 位图像素数据的 HBITMAP 以避免额外的复制,并从中创建 BitBlt 吗?
最佳答案
搜索了几天后,我突然意识到答案一直在我面前!我正在从指向字节数组的指针创建 GDI+ 位图。然后尝试使用相同的指针创建 HBITMAP。但我可以先轻松创建 HBITMAP,然后使用其中的指针来创建 GDI+ 位图。
它就像一个魅力!您可以随意混合 GDI 和 GDI+ 操作。该图像同时是普通 GDI 和 GDI+。您可以使用完全相同的像素数据进行 BitBlt,而不是使用 DrawImage!
代码如下:
// Create the HBITMAP
BITMAPINFO binfo = new BITMAPINFO();
binfo.biSize = (uint)Marshal.SizeOf(typeof(BITMAPINFO));
binfo.biWidth = width;
binfo.biHeight = height;
binfo.biBitCount = (ushort)Image.GetPixelFormatSize(pixelFormat);
binfo.biPlanes = 1;
binfo.biCompression = 0;
hDC = CreateCompatibleDC(IntPtr.Zero);
IntPtr pointer;
hBitmap = CreateDIBSection(hDC, ref binfo, 0, out pointer, IntPtr.Zero, 0);
// Create the GDI+ bitmap using the pointer returned from CreateDIBSection
gdiBitmap = new Bitmap(width, height, width * binfo.biBitCount >> 3, pixelFormat, pointer);
关于winapi - 是否可以直接从 GDI+ 位图进行 BitBlt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4588132/