-
July 23rd, 2013, 09:01 AM
#1
Merging two Gdiplus::Bitmap into one c++
I'm trying to merge two Gdiplus::Bitmap and save result to disk.
pbmBitmap - is Gdiplus::Bitmap
At start i was trying to copy one bitmap into another and save copied bitmap to disk. Here is my code:
Code:
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
It should work, but i get 24kb black bitmap.
SaveBitmap is my custom function, it works when i try save source bitmap.
Why i can't copy one bitmap to another??
-
July 23rd, 2013, 12:37 PM
#2
Re: Merging two Gdiplus::Bitmap into one c++
Don't you find it strange to select a dc to self while with source dc you select a bitmap?
Best regards,
Igor
-
July 23rd, 2013, 02:52 PM
#3
Re: Merging two Gdiplus::Bitmap into one c++
My bad, i did some modifications before i copied my code to forum.
Anyway i solve it by creating Gdiplus::Bitmap of destination bitmat then get his HBITMAP and select in device context.
I don't know why CreateCompatibleBitmap isn't working for me.
-
July 24th, 2013, 01:39 PM
#4
Re: Merging two Gdiplus::Bitmap into one c++
Your bitmap needs to be created compatible with some real (color) dc but not just newly created one. New dc contains a monochrome bitmap selected by default.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|