Cags Posted August 1, 2006 Posted August 1, 2006 Now maybe i'm 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. I'm wondering if it might be a problem with using GraphicsUnit.Pixel.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); } Quote Anybody looking for a graduate programmer (Midlands, England)?
Cags Posted August 1, 2006 Author Posted August 1, 2006 Well I've worked out the problem goes away if I specify the targets width and height (by using the overload that excepts the targetRect rather than x and y). This seems odd to me as if the source is that size I assumed it would make the target that size. Perhaps it's down to DPI if anyone can explain it please post. Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.