I am doing some image scaling using GDI + (C #) and noticed a problem when the image that I am scaling is cropped along the left and top edges.
http://zctut.com/cutoff.png
To reproduce this, create a new form project, save this image in the bin \ debug folder and add the following code to the form (and, accordingly, events):
public partial class Form1 : Form { public Form1() { InitializeComponent(); } int scale = 1; Image img = Image.FromFile("circle.png"); private void Form1_Paint(object sender, PaintEventArgs e) {
As you can see, the left and top rows of pixels are cropped as if the zoom rectangle started halfway in the pixel.
Edit: for the note, I also tried using scale transformation instead of using rectangles as above, and it got exactly the same.
Now, having said that, I have found a job. If you change the rectangle declarations in the example above, follow these steps:
RectangleF srcRect = new RectangleF(-0.5f, -0.5f, img.Width, img.Height);
So that we correct the "half", the image is displayed correctly.
Basically, although this is easy to get around, am I doing something wrong or is this normal behavior?
Edit: as suggested by Andrei Pana, I tried to add this code before calling the drawing:
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
And, unfortunately, this did not affect the rendering. The edge was still cut off.