Hello again!
I want to make an image viewer for files with a simple uncompressed RGBA file structure.
That means it has an unimportant header followed by packs of 4 bytes for R,G,B and A for every pixel of the image.
Well, I was playing around with the SetPixel() function and had to notice that the creation of a filled 200x200 box like:
is a cpu killer as if I move the window or loose focus the app is taking 60% - 100% cpu and the longer the process stays and the more often I move the window around it is lagging more and more until it freezes (sometimes).Code:case WM_PAINT: int pixel_x, pixel_y; for (pixel_x = 100; pixel_x < 300; pixel_x++) { for (pixel_y = 100; pixel_y < 300; pixel_y++) { SetPixel(hdc1,pixel_y,pixel_x,0xFFFF00); } } break;
So... is there a better way of drawing the picture out of the file? What are the other programs doing like ms paint? I know bmp, jpg, png etc formats are not uncompressed but you can still do anything laglessly in ms paint independant of the pictures attributes...
There must be a way of saving the created pixels permanently (as one image or something), so the app doesn't always have to redraw all of them... or probably a completely other method instead of SetPixel()... also, how do I include the alpha transparency? It doesn't seem to work with only SetPixel().
Thanks for any help!
Hawk
Edit:
I included BeginPaint() and EndPaint() tags and a "PAINTSTRUCT" and it has gotten better, but still: Is there a better method in doing this? And also, how can I include the alpha opaque/transparency now?