How can I speed up painting?

RcSepp
05-06-2006, 10:27 AM
Hi everyone

As one of the many people who try to make their own custom MS Paint I searched through this forum and found a nice methode of drawing without using the paint event (using graphics on a bitmap and copy the bitmap to the picturebox.image). But now I have two big problemes with that:

1: If I resize the picturebox after drawing a bit, I must make the bitmap bigger too to get a bigger space to draw on, but I haven't found out how to do that (bitmaps width and height properties are readonly).

2: The only way to get around point 1 would be to make the bitmap as large as the users screen at the beginning. If I do that, the painting methode gets really slow. Even if I solved point 1, there would still be the problem that the program gets too slow if the user draws on a big picturebox.

Please help me. Any methodes to speed this up are welcome, even if I had to rewrite my hole program.

Thanks for help
RcSepp

JNewt
05-06-2006, 11:54 AM
When the bitmap needs to be resized, do this:

backbufferBMP=New Bitmap(newWidth, newHeight)
backbufferGFX=Graphics.FromImage(backbufferBMP)

Rockoon
05-06-2006, 06:02 PM
1) Create a new bitmap with the new size and copy the old bitmap pixels into it.
2) Only redraw actual changes to the bitmap. Usualy this is done with "dirty rectangles" for efficiency reasons.

RcSepp
05-07-2006, 02:01 AM
Thanks for help.
Just one more question:
If I resize my picturebox and make the backbufferBMP as you said, I would have to tell my whole code, that now I all work will now be done with the backbufferBMP. Is there a way to get my original bitmap to the size of the backbufferBMP, because otherwise I would have to always create a new backbufferBMP after every resizing.

RcSepp
05-07-2006, 03:43 AM
Ok, I found the problem.
You must not always make a new bmp. That was just because of my buggy code.

Sorry for that
RcSepp

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum