Resizing an image

Asked

Viewed 30 times

0

I’m trying to resize an image with this code.

    public static Bitmap ResizeImage(Image image, int width)
    {
        var destRect = new Rectangle(0, 0, width, image.Height);
        var destImage = new Bitmap(width, image.Height);

        destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

        using (var graphics = Graphics.FromImage(destImage))
        {
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            graphics.DrawImage(image, destRect);
        }

        return destImage;
    }

However, she is losing quality. This image shows the original barcode (277 pixels wide) at the top and the resized (270 wide) at the bottom.

im

  • what width are you going through and what formats are you getting, how are you saving? in my tests here not granulou

  • I am using zxing to generate barcode. Any width I place is not respected. The image is always 277 wide.

  • 1

    This is showing me a question in your printer and not in the code

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.