Cags
Well-known member
Now maybe im being stupid, but this is driving me really nuts...
Insert the following code onto a normal form and let me know if you see anything strange when you load an image. For the smart-arses amonst you, feel free to tell me whats wrong by just looking at the code . Basically the images are drawing all wrong. Im wondering if it might be a problem with using GraphicsUnit.Pixel.
Insert the following code onto a normal form and let me know if you see anything strange when you load an image. For the smart-arses amonst you, feel free to tell me whats wrong by just looking at the code . Basically the images are drawing all wrong. Im wondering if it might be a problem with using GraphicsUnit.Pixel.
C#:
public Bitmap SourceImage;
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.Black);
if(SourceImage != null)
{
for(int i = 0; i < 4; i++)
{
Rectangle bounds = new Rectangle(i * 60, 0, 60, 240);
e.Graphics.DrawImage(SourceImage, bounds.X, bounds.Y, bounds, GraphicsUnit.Pixel);
}
e.Graphics.DrawImage(SourceImage, 240, 0, new Rectangle(0, 0, 240, 240), GraphicsUnit.Pixel);
e.Graphics.DrawString("Drawn in strips", new Font("Tahoma", 12), new SolidBrush(Color.White), 5, 5);
e.Graphics.DrawString("Drawn as one", new Font("Tahoma", 12), new SolidBrush(Color.White), 245, 5);
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// avoid flicker
}
protected override void OnLoad(EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
// load an image for demonstration purposes
if(openDialog.ShowDialog() == DialogResult.OK)
{
SourceImage = new Bitmap(openDialog.FileName);
}
this.ClientSize = new Size(480, 240);
}