stop Refreshing of images drawn by setpixel() and saving it how to do?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: stop Refreshing of images drawn by setpixel() and saving it how to do?

  1. #1
    Join Date
    Jun 2012
    Posts
    37

    stop Refreshing of images drawn by setpixel() and saving it how to do?

    Code:
    ONDRAW(CDC *pDC)
    for(int y=0; y<=600; y++)
     {
    	for(int x=0; x<=600; x++)
    	pDC->SetPixel(x,y,RGB(0,255,0));
     }
    This code draw a rectange of green colour. This image gets refreshed everytime whenever it is resized.
    As far as i could knoew is WM_PAINT is ahandler which call ONDRAW() through ONPAINT().. Correct me if I am wrong.

    Now How do i avoid this refreshing of images. also How will I save this bitmap image generated using setpixel(). Please any one could suggest me and help me out.

    FYI I am a learner in visual C++ and I am learning it by solving some of my own problems and examples framed by myself.

  2. #2
    Join Date
    Jun 2012
    Posts
    37

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Wether it is possible or not?? I am waiting for some ideas or hints or some understanding..

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Why are you setting it pixel by pixel ? With FillSolidRect you can do the same, and it's MUCH faster.

  4. #4
    Join Date
    Jun 2012
    Posts
    37

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Quote Originally Posted by Skizmo View Post
    Why are you setting it pixel by pixel ? With FillSolidRect you can do the same, and it's MUCH faster.
    I know that but my purpose is difeerent. Say i am plotting based on a data a 2-d contour plot I have to go pixel wise since i have data at each point ie pixel. At that moment i cannot avoid it. Can you or any please suggest any solution or idea

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,525

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    You should read about flicker-free drawing using double buffering.
    In short, you plot your data on the off-screen DC and use BitBlt() in your OnDraw() to paint it on screen.
    You would also need to handle WM_ERASEBACKGROUND message to preventing that erase background.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Quote Originally Posted by tarkes View Post
    ... Now How do i avoid this refreshing of images. ... As far as i could knoew is WM_PAINT is ahandler
    The whole purpose of the WM_PAINT handler is to refresh the image. So why do you want to avoid it?

    Quote Originally Posted by tarkes View Post
    ... also How will I save this bitmap image ...
    This is an entirely different question. Solve your first question first, since it doesn't make sense to save something that isn't what you want. After you solve your first question, then perhaps Google for the CImage class, which might help you.

    Mike

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    This is an entirely different question. Solve your first question first
    Actually... if he has the answer to this question, he can solve the problem of the first question. My guess about why he wants to avoid the refresh is that the SetPixel function is horribly slow. So if he knows how to write it to an image and use that as a cached image, the problem of the slow SetPixel will be gone

  8. #8
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Aha, I see. I think you're right. I interpreted his mention of "save" as in a "save to disk", not a "save in memory for a quick re-draw".

    Mike

  9. #9
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    @tarkes, assuming that Skizmo is right (he usually is), then you might still benefit from the CImage class mentioned above, see http://msdn.microsoft.com/en-us/libr...ea7by5(v=vs.80)

    The idea is this: Let a CImage object be a member of your class. Draw your 2-d contour into the CImage using CImage::SetPixel. This needs to be done only once. Then, in your OnDraw handler for WM_PAINT, call CImage::BitBlt to blt the contents of the CImage bitmap into the device context provided.

    Mike

  10. #10
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Assuming skizmo isn't right

    Windows will trigger a WM_PAINT message whenever something has happened that has invalidated any part of the window.
    If you size the window (smaller or larger), then the default behaviour of Windows isi that the entire window will be marked invalid.
    If some other window is overlapping your window and that window gets moved, again, that part of the window will be invalidated.
    If your window has scrollbars, and the scrollbars are pressed that invalidates the window.
    And finally, your own program can explicitely invalidate parts of a window via the InvalidateRect() function.

    When a part of a window is invalid, a WM_PAINT will be "in the queue" (it isn't actually there).

    You seem to be using MFC, so this WM_PAINT is usually handled in OnPaint, for some controls, MFC will do some preliminary work for you, and you have a somewhat simpler OnDraw() function to do your drawing stuff.


    Now... All that stuff above about part of a window getting invalidated... you can override this default behaviour and prevent this invalidation. THe problem of course is that this will make your application look somewhat funny/weird, unless you also do "something" in the areas that would have been invalidated. Applications can use this behaviour to prevent flicker and get more performance by not having to redraw bits of the screen that don't need to be repainted.
    It is a somewhat more advanced topic, and not something for a learning programmer, you need a substantial amount of code in place (several hundred lines of code at least) to handle all the special cases.


    That said.
    SetPixel is really really really slow. The solution is indeed to make a bitmap, and twiddle the bits in this bitmap, and paint the bitmap with BitBlt as it is needed. CImage is one way to to it. If you can't afford to use GDI+, the other way would be to use CreateDIDSection().

  11. #11
    Join Date
    Jun 2012
    Posts
    37

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Quote Originally Posted by MikeAThon View Post
    Aha, I see. I think you're right. I interpreted his mention of "save" as in a "save to disk", not a "save in memory for a quick re-draw".

    Mike
    There has been lot of discussion goin on these. Soory I was bit out for 2 days. I was not in a position to check the post.
    My aim is:
    1. Display the image without refreshment i.e. what save in cache memory and display.

    2. Save into disk if it is possible so.

    3. Presence of scroll bar in window if the image is large than SDI window.

    I have not read the posts thourughly. Let me go through it and get some hints if possible.

  12. #12
    Join Date
    Jun 2012
    Posts
    37

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Unfortuanately I am using VC++ 6.

    http://social.msdn.microsoft.com/For...8-9a09af6044e5

    What is find there is no CImage class being defined in VC++ 6. Can anyone suggest me in regard to this.
    Waiting for any reply

  13. #13
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    1) This requires a "off screen bitmap" which you then blit to screen.
    It avoids the whole pixel by pixel thing entirely.

    2) THen I'd go with the CImage GDI+ solution posted. You can do this with the CreateDIBSection() solution also, but saving an image that's usuable/displayable in other programs is a bit more complex.

    3) I would recommend you look at the CScrollView class as base class for your SDI window. This'll take care of most of the scrolling stuff for you. All you need to do is set your desired size (600x600), and you provide the OnDraw function, MFC will take care of the rest adequately enough for a starter program. Though you can improve on what it does.

  14. #14
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    for VC++ 6.
    You can still make use of gdi+, you just need to have the headers and library installed.
    http://www.microsoft.com/en-us/downl....aspx?id=18909

  15. #15
    Join Date
    Jun 2012
    Posts
    37

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    Quote Originally Posted by OReubens View Post
    for VC++ 6.
    You can still make use of gdi+, you just need to have the headers and library installed.
    http://www.microsoft.com/en-us/downl....aspx?id=18909
    I had downladed the setup filw which is of 852kb. what should be the directory of setup. and for a trial i just extracted it but i dont find any header files .h as such. please kindly can u assist me

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center