搜索了几天之后,它突然袭击了我,答案一直盯着我的脸!我是从指向字节数组的指针创建GDI +位图.然后尝试使用相同的指针创建HBITMAP.但我可以先轻松创建HBITMAP并使用指针来创建GDI +位图.
它就像一个魅力!您可以随意混合使用GDI和GDI +操作.图像既是普通的GDI,也是GDI +.而不是使用DrawImage,你可以从完全相同的像素数据BitBlt!
这是代码:
// 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4836 次 |
| 最近记录: |