2

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?

PookyFan
  • 785
  • 1
  • 8
  • 23
  • The flipping logic looks right. By "*nothing happens*", do you mean no image at all? And no image without the negative height either? Presumably you have something else wrong... – mark May 30 '13 at 16:00
  • Well when I tried to change some parameters I got, for example, completely dark image. These parameters I shown with my code seem to be correct, but instead of flipped image I'm getting the same image all the time, unchanged. – PookyFan May 30 '13 at 16:06

1 Answers1

7

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);
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • Should this be pdc, 0, h-1, w, -h, dc, ... ? The first line would be the end which is h-1...? – Todd Nov 26 '20 at 23:48