何日も探した後、突然、答えがずっと私をじっと見つめていたことに気づきました!ポインタからバイト配列への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);