dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Moving a bitmap

  1. #1
    Join Date
    Nov 2005
    Posts
    159

    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

    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

  2. #2
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    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.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  3. #3
    Join Date
    Nov 2005
    Posts
    159

    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.

  4. #4
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    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.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  5. #5
    Join Date
    Nov 2005
    Posts
    159

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)