高质量图像缩放 [英] High quality image scaling
问题描述
我已经阅读了以下问题,高质量图像缩放库,但是它仅适用于GDI +.
I have read this question, High Quality Image Scaling Library , but it only pertains to GDI+.
当我在应用程序中按比例缩小Image
时,它变得非常锯齿.
When I scale down an Image
in my app, it becomes very jaggy.
在Image
类上找不到任何可以提高降级质量的属性.
I can't find any property on the Image
class that allows me to increase the quality of the down-scaling.
我该怎么做?
我现在使用了以下代码:
I have now used this code:
BitmapImage img = new BitmapImage();
img.UriSource = new Uri(Graphic, UriKind.Relative);
return img;
其中Graphic
是string
,其中包含图像的路径,但出现此异常:
where Graphic
is a string
that contains the path to the image, but am getting this exception:
Weather.DLL中发生了'System.ArgumentException'类型的异常,但未在用户代码中处理
An exception of type 'System.ArgumentException' occurred in Weather.DLL but was not handled in user code
其他信息:无法将给定的System.Uri转换为Windows.Foundation.Uri.请参阅> http://go.microsoft.com/fwlink/?LinkID=215849 了解详情.
Additional information: The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details.
据我所知,.net
框架中未使用Windows.Foundation.Uri
.
As far as I know, Windows.Foundation.Uri
isn't used in the .net
framework.
那为什么会给我这个错误?
So why is it giving me this error?
推荐答案
在XAML中:
<Image Width="250" Height="250" Stretch="UniformToFill">
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" DecodePixelHeight="250"/>
</Image.Source>
</Image>
在C#中:
BitmapImage bitmapImage = BitmapImage("URL HERE");
bitmapImage.DecodePixelHeight = 250;
仅设置DecodePixelHeight或DecodePixelWidth.
Only set DecodePixelHeight or DecodePixelWidth.
这篇关于高质量图像缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!