0

I'm trying to resize an image wihout loosing quality. I use code from here

Bitmap newImage = new Bitmap(newWidth, newHeight);
using (Graphics gr = Graphics.FromImage(newImage))
{
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));
}

But I got strange problem: a 1px border around the image.

Original image: Original image

Resized: enter image description here

Not easy to see it, but when you zoom image you can note it, especially in the top-left corner.

How to get rid of it? What is the problem?

Thx!

adrenalin
  • 135
  • 1
  • 12
  • Just a guess, but try `gr,CompositingMode = Drawing2D.CompositingMode.SourceCopy`. – TnTinMn Jun 08 '17 at 14:15
  • @TnTinMn, thx, but the problem remains. exactly the same result... – adrenalin Jun 08 '17 at 14:47
  • Not so sure I'm looking at the right problem, but they are almost surely interpolation artifacts. An aliasing problem, caused by the interpolator running out of pixels to interpolate at the edge of the bitmap. Very similar to the kind of ringing you get when sampling a digital signal. Only a lower quality choice can reduce it. – Hans Passant Jun 08 '17 at 15:01
  • @HansPassant, thx. But I need to resize image without loosing quality... I have good result when I resize it in paint.net - good quality and no borders... – adrenalin Jun 09 '17 at 06:54

0 Answers0