A problem with graphics
I have been playing around with some basic graphic elements to get in touch with OOP and C#. i have managed to put the following piece of code together but am experiencing an unusual issue with it.
Nothing spectacular in there as you can see (well to someone who is used to it anyway - which im not).
public partial class Form1 : Form
public int xpos = 10;
public int ypos = 10;
Bitmap myBitmap = new Bitmap(@"c:\green_ball.bmp"); //64 x 64 pixel images
Bitmap myBitmap1 = new Bitmap(@"c:\wall1.bmp");
Bitmap myBitmap2 = new Bitmap(@"c:\brown_ball.bmp");
public Graphics g;
private Bitmap myscreen;
myscreen = draw();
public Bitmap draw()
Bitmap back = new Bitmap(this.Width, this.Height);
Graphics p = Graphics.FromImage(back);
int tile = 1;
for (y = 0; y <= 640; y = y + 64)
for (x = 0; x <= 768; x = x + 64)
if (tile == 1)
p.DrawImage(myBitmap1, x, y);
tile = 0;
p.DrawImage(myBitmap2, x, y);
tile = 1;
p.DrawImage(myBitmap, xpos, ypos);
return (back) ;
private void Form1_KeyDown(object sender, KeyEventArgs e)
string key = e.KeyData.ToString();
if (key == "Right")
xpos = xpos +4;
else if (key == "Left")
xpos = xpos -4;
else if (key == "Up")
ypos = ypos -4;
else if (key == "Down")
ypos = ypos +4;
myscreen = draw();
private void Form1_Paint(object sender, PaintEventArgs e)
// its overridden
protected override void OnPaint(PaintEventArgs e)
e.Graphics.DrawImage(this.myscreen, 0, 0);
My problem is this, in the draw routine, the three lines which turn on transparency (highlighted) seem to affect the actual size of the graphics the system draws.
Is it supposed to affect the size ?
when i comment them out, i get graphics about 1/4 of the dimension i get when uncommented. Can anyone shed any light on this ?
it does not affect the actual execution of the code in anyother way i can see.
thanks in advance.
Just as a note to this as it got no replys - i believe the issue was something to do with different DPI resolution settings on the images but am still not 100%