Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 3.0 C#图像大小-质量损失_C# 3.0 - Fatal编程技术网

C# 3.0 C#图像大小-质量损失

C# 3.0 C#图像大小-质量损失,c#-3.0,C# 3.0,我使用了C#方法来调整图像大小 缩小 但在重新调整图像大小时,质量缺失 请帮助我解决此问题。您可以使用(Windows Imaging Component)而不是GDI+。下面是一个示例。首先将位图转换为图像 Bitmap b = new Bitmap("asdf.jpg"); Image i = (Image)b; 然后将图像传递给此方法以调整大小 public static Image ResizeImage(Image image, int width, int height, bo

我使用了C#方法来调整图像大小

缩小

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


请帮助我解决此问题。

您可以使用(Windows Imaging Component)而不是GDI+。下面是一个示例。

首先将
位图
转换为
图像

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;
    }
}
公共静态图像大小图像(图像图像、整型宽度、整型高度、仅限布尔值ResizeIfWidth)
{
使用(图像)
{
//防止使用图像内部缩略图。
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
if(仅限ResizeIfWider==true)
如果(图像宽度高度)
{
宽度=图像。宽度*高度/图像。高度;
新高度=高度;
}
Image NewImage=Image.GetThumbnailImage(宽度,newHeight,null,IntPtr.Zero);
返回新图像;
}
}

我希望这能有所帮助。

其中一个可能的副本看到了这一点