是否可以使用 BitBlt 直接从 GDI+ 位图中复制而不使用 GetHBitmap?
GetHBitmap 很慢,因为它除了 BitBlt 副本之外还创建整个图像的新副本,并且比 BitBlt 副本慢,并且必须处理给定的 HBITMAP。图像很大。
有没有办法让BitBlt使用原始GDI+图像的像素数据?
EDIT:我可以获得指向 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)