我有两个位图:
Gdiplus::Bitmap *pbmBitmap, pbmBitmap1;
它们包含两个图像。我如何将它们合并为一张图像?
我正在尝试这样的事情:
Bitmap* dstBitmap = new Bitmap(pbmBitmap->GetWidth(), pbmBitmap->GetHeight() + pbmBitmap1->GetHeight()); //create dst bitmap
HDC dcmem = CreateCompatibleDC(NULL);
SelectObject(dcmem, pbmBitmap); //select first bitmap
HDC dcmemDst = CreateCompatibleDC(NULL);
SelectObject(dcmem1, dstBitmap ); //select destination bitmap
BitBlt(dcmemDst em1, 0, 0, pbmBitmap->GetWidth(), pbmBitmap->GetHeight(), dcmem, 0, 0, SRCCOPY); //copy first bitmap into destination bitmap
HBITMAP CreatedBitmap = CreateCompatibleBitmap(dcmem, pbmBitmap->GetWidth(), pbmBitmap->GetHeight() + pbmBitmap1->GetHeight());
dstBitmap = new Bitmap(CreatedBitmap, NULL);
dstBitmap ->Save(L"omg.bmp", &pngClsid, 0); //pngClsid i took from msdn
我知道 - 丑陋的代码,但我需要用 C++ 来做。我得到黑色图像。为什么?
//编辑
经过两个小时的谷歌搜索和阅读,我得到了这个:
HBITMAP bitmapSource;
pbmBitmap->GetHBITMAP(Color::White, &bitmapSource); //create HBITMAP from Gdiplus::Bitmap
HDC dcDestination = CreateCompatibleDC(NULL); //create device contex for our destination bitmap
HBITMAP HBitmapDestination = CreateCompatibleBitmap(dcDestination, pbmBitmap->GetWidth(), pbmBitmap->GetHeight()); //create HBITMAP with correct size
SelectObject(dcDestination, dcDestination); //select created hbitmap on our destination dc
HDC dcSource = CreateCompatibleDC(NULL); //create device contex for our source bitmap
SelectObject(dcSource, bitmapSource); //select source bitmap on our source dc
BitBlt(dcDestination, 0, 0, pbmBitmap->GetWidth(), pbmBitmap->GetHeight(), dcSource, 0, 0, SRCCOPY); //copy piece of bitmap with correct size
SaveBitmap(dcDestination, HBitmapDestination, "OMG.bmp"); //not working i get 24kb bitmap
//SaveBitmap(dcSource, bitmapSource, "OMG.bmp"); //works like a boss, so it's problem with SaveBitmap function
它应该可以工作,但我得到 24kb 位图。SaveBitmap 是我的自定义函数,当我尝试保存源位图时它可以工作。为什么我不能将一个位图复制到另一个位图?