CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2013
    Posts
    2

    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??

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  3. #3
    Join Date
    Jul 2013
    Posts
    2

    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.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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
  •  





Click Here to Expand Forum to Full Width

Featured