I'm writing a fairly simple two-player puzzle game. I have a background
image in a PNG file (44 KB, 160 x 320 pixels) which I load into an Image
object ...
imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file
The Image is then painted onto two PictureBoxes several times a second ...
Graphics g = e.Graphics;
g.DrawImageUnsc aled(imgCachedB ackground, 0, 0);
I have provided the option of playing at double size (so that the
PictureBox, background, etc. double up to 320 x 640 pixels). Rather than
scaling the image in each Paint event, I store and use a double-size image,
like this.
imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file
if (iSizeRatio > 1) // i.e. 2 for double size
{
imgCachedBackgr ound = new Bitmap(
imgCachedBackgr ound, new Size(
iSizeRatio * imgCachedBackgr ound.Width,
iSizeRatio * imgCachedBackgr ound.Height));
}
(The image is only cached once, not in every Paint event!)
The speed is fine for two players at single size and for one player at
double size, but when both PictureBoxes are at double size there is a major
drop in speed.
Can anyone explain this or suggest how I might do it more efficiently?
P.
--
www.CL4.org