-
June 7th, 2012, 01:54 AM
#1
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.
-
June 7th, 2012, 06:35 AM
#2
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..
-
June 7th, 2012, 07:23 AM
#3
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.
-
June 7th, 2012, 09:26 AM
#4
Re: stop Refreshing of images drawn by setpixel() and saving it how to do?
Originally Posted by Skizmo
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
-
June 7th, 2012, 11:36 AM
#5
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 8th, 2012, 12:10 PM
#6
Re: stop Refreshing of images drawn by setpixel() and saving it how to do?
Originally Posted by tarkes
... 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?
Originally Posted by tarkes
... 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
-
June 8th, 2012, 05:28 PM
#7
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
-
June 8th, 2012, 05:40 PM
#8
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
-
June 8th, 2012, 05:52 PM
#9
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
-
June 9th, 2012, 06:16 AM
#10
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().
-
June 9th, 2012, 08:18 AM
#11
Re: stop Refreshing of images drawn by setpixel() and saving it how to do?
Originally Posted by MikeAThon
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.
-
June 9th, 2012, 08:53 AM
#12
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
-
June 9th, 2012, 08:54 AM
#13
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.
-
June 9th, 2012, 09:00 AM
#14
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
-
June 9th, 2012, 07:51 PM
#15
Re: stop Refreshing of images drawn by setpixel() and saving it how to do?
Originally Posted by OReubens
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|