-
Moving a bitmap
Hi all,
What I'm asking is probably simple but I don't seem to find the solution. Google gave me a lot, but not what I was looking for :sick:
For a small application I need something like an oscilloscope view. I was thinking about shifting the view one pixel to the left and then draw the new value on the right.
My problem is that I don't find how to shift/move the whole bitmap one pixel to the left. Of course I would like to do it in the most efficient way.
I am currently storing the bitmap as a HBITMAP and loading it in a memory device context to draw on it.
Thanks in advance,
Jef
-
Re: Moving a bitmap
Hello,
One method is to store the current window as a bitmap in memory device context and paste it on the window with its coordinates moved left by one pixel.
Regards,
Pravin.
-
Re: Moving a bitmap
For several reasons I need to do it all in the memory device context. I need to pass the bitmap to a framework, so I really need to edit the bitmap. I do not have the possibility to paste it differently on the screen.
-
Re: Moving a bitmap
Hello,
You may shift the window contents to one pixel left with the code mentioned below.
Code:
CRect Rect;
GetClientRect(Rect);
CDC MemDC;
CClientDC DC(this);
if (MemDC.CreateCompatibleDC(&DC))
{
CBitmap BM;
if (BM.CreateCompatibleBitmap(&DC, Rect.Width(), Rect.Height()))
{
CBitmap* pBM = MemDC.SelectObject(&BM);
MemDC.BitBlt(0, 0, Rect.Width(), Rect.Height(),
&DC, 0, 0, SRCCOPY);
DC.BitBlt(-1, 0, Rect.Width(), Rect.Height(),
&MemDC, 0, 0, SRCCOPY);
MemDC.SelectObject(pBM);
BM.DeleteObject();
}
MemDC.DeleteDC();
}
Now, you can do what you want to plot at the right end of the window. If you put the whole code in a WM_TIMER message handler, this will give the effect of movement.
Regards,
Pravin.
-
Re: Moving a bitmap
Thanks, you put me on the right track. I have it solved now and it runs as I wished.
greetings,
Jef