0

我使用了 C# 方法来调整图像大小。我使用了以下链接中的几种方法。

C# Simple Image Resize:文件大小不 缩小

调整图像大小 C#

但是重新调整图像大小时质量缺失

请帮我解决问题。

4

2 回答 2

0

您可以使用WIC(Windows 映像组件)而不是 GDI+。这是一个带有示例的不错的博客文章。

于 2012-06-22T07:40:26.963 回答
0

首先将您的转换BitmapImage

Bitmap b = new Bitmap("asdf.jpg");
Image i = (Image)b;

然后将图像传递给此方法以调整大小

public static Image ResizeImage(Image image, int width, int height, bool onlyResizeIfWider)
{
    using (image)
    {
        // Prevent using images internal thumbnail.
        image.RotateFlip(RotateFlipType.Rotate180FlipNone);
        image.RotateFlip(RotateFlipType.Rotate180FlipNone);

        if (onlyResizeIfWider == true)
            if (image.Width <= width)
                width = image.Width;

        // Resize with height instead?
        int newHeight = image.Height * width / image.Width;
        if (newHeight > height)
        {
            width = image.Width * height / image.Height;
            newHeight = height;
        }
        Image NewImage = image.GetThumbnailImage(width, newHeight, null, IntPtr.Zero);
        return NewImage;
    }
}

我希望这有帮助。

于 2012-06-22T07:44:42.753 回答