WPF:选择jpg,调整大小然后保存?最佳选择? [英] WPF: Selecting a jpg, resizing it and then saving it? Best option?

查看:245
本文介绍了WPF:选择jpg,调整大小然后保存?最佳选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道拍摄所选图像,调整大小并保存它的最佳方法是什么。据我所知,WPF在调整图像大小时会破坏图像质量。这是真的,如果是这样我应该尝试什么方法来尝试这个任务?

I was wondering what is the best way to go about taking a selected image, resizing it and saving it. From what i have heard WPF destroys image quality when it resizes images. Is this true, if so what method should i try to attempt this task?

谢谢,Kohan。

推荐答案

WPF旨在能够实时调整图像大小以进行显示(使用图形卡加速),因此偏向速度而非质量。

WPF is designed to be able to resize images in real time for display (using graphics card acceleration) and so is biased towards speed over quality.

如果你想要体面的品质,你应该使用 System.Drawing.Bitmap 进行大小调整:

If you want decent quality you should use System.Drawing.Bitmap to do your resizing:

System.Drawing.Bitmap resizedImage;

using(System.Drawing.Image originalImage = System.Drawing.Image.FromFile(filePath))
    resizedImage = new System.Drawing.Bitmap(originalImage, newSize);

// Save resized picture
resizedImage.Save(resizedFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
resizedImage.Dispose();

质量仍然不会很好 - JPEG是一种有损的图像格式,保真度将会丢失加载和保存以及位图类粗缩放。如果质量必须尽可能高,那么你应该考虑使用一个成像库,如 DevIL ,这将做更好地生成平滑调整大小的图像。

The quality still won't be great - JPEG is a lossy image format and fidelity will be lost by loading and saving and also by the Bitmap classes crude scaling. If quality must be as high as possible then you should consider using an imaging library such as DevIL, which will do a better job of producing a smoothly resized image.

这篇关于WPF:选择jpg,调整大小然后保存?最佳选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆