Question

According to MSDN:

StretchBlt creates a mirror image of a bitmap if the signs of the nWidthSrc and nWidthDest parameters or if the nHeightSrc and nHeightDest parameters differ.

So I tried creating upside-down image. I have a class looking like this:

class Picture
{
 private:
 HBITMAP bmp; //Bitmap
 HDC pdc; //Device context
 short int w; //Weidth of bitmap
 short int h; //Heighth of bitmap

 public:
 short int x;
 short int y;
 void draw(HDC);
 void upside_down();
}

and I have this method:

void Picture::upside_down()
{
 HDC dc = CreateCompatibleDC(pdc);
 HBITMAP bmap = CreateCompatibleBitmap(pdc, w, h);
 SelectObject(dc, bmap);
 BitBlt(dc, 0, 0, w, h, pdc, 0, 0, SRCCOPY);
 StretchBlt(pdc, 0, 0, w, h, dc, 0, 0, w, -h, SRCCOPY);
 DeleteDC(dc);
 DeleteObject(bmap);
}

but it doesn't work, nothing happens. I wonder if it's something with DC compability, I've always had problems understanding the logic behind that.

So, what should I do so I could get my bitmap flipped?

Was it helpful?

Solution

To flip the picture, you don't negate the height of the source -- you negate the height of the destination. To go with this, you have to specify the bottom of your destination rectangle as the origin, so your call would looks something like this:

StretchBlt(pdc, 0, h, w, -h, dc, 0, 0, w, h, SRCCOPY);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top