P
Paul E Collins
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 ...
imgCachedBackground = Image.FromFile(strImageFilename); // a PNG file
The Image is then painted onto two PictureBoxes several times a second ...
Graphics g = e.Graphics;
g.DrawImageUnscaled(imgCachedBackground, 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.
imgCachedBackground = Image.FromFile(strImageFilename); // a PNG file
if (iSizeRatio > 1) // i.e. 2 for double size
{
imgCachedBackground = new Bitmap(
imgCachedBackground, new Size(
iSizeRatio * imgCachedBackground.Width,
iSizeRatio * imgCachedBackground.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.
image in a PNG file (44 KB, 160 x 320 pixels) which I load into an Image
object ...
imgCachedBackground = Image.FromFile(strImageFilename); // a PNG file
The Image is then painted onto two PictureBoxes several times a second ...
Graphics g = e.Graphics;
g.DrawImageUnscaled(imgCachedBackground, 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.
imgCachedBackground = Image.FromFile(strImageFilename); // a PNG file
if (iSizeRatio > 1) // i.e. 2 for double size
{
imgCachedBackground = new Bitmap(
imgCachedBackground, new Size(
iSizeRatio * imgCachedBackground.Width,
iSizeRatio * imgCachedBackground.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.