Strange problem about conversion between GDI+ to GDI: Bitmap and HBitmap


I want to convert gdi+ Bitmap into gdi object HBitmap.

I am using the following method:

   Bitmap* img = new Bitmap(XXX);
            // lots of codes...
    HBITMAP temp;
    Color color;
    img->GetHBITMAP(color, &temp);

the img object is drawing on a dialog.
when this part of method is called, strange thing happens!
the img displaying in the window changed!
It become a bit clearer or sharper.
My question is what happens?

Best Solution

The bitmap pixel format may be the reason. Do you specify it explicitly in the Bitmap constructor?

Gdiplus::Bitmap bmp(WIDTH, HEIGHT, PixelFormat24bppRGB);

Try making sure that all the pixel formats you use are the same.

Another reason may be the differences in Gdiplus::Graphics interpolation modes in your code. That attribute determines how the images are resized, how the lines are drawn, etc.

m_pViewPortImage = new Gdiplus::Bitmap(

Gdiplus::Graphics gr(m_pViewPortImage);
Related Question