High quality image scaling

老子叫甜甜 提交于 2019-12-24 03:18:20

问题


I have read this question, High Quality Image Scaling Library , but it only pertains to GDI+.

When I scale down an Image in my app, it becomes very jaggy.

I can't find any property on the Image class that allows me to increase the quality of the down-scaling.

How can I do this?

EDIT:

I have now used this code:

BitmapImage img = new BitmapImage();
img.UriSource = new Uri(Graphic, UriKind.Relative);
return img;

where Graphic is a string that contains the path to the image, but am getting this exception:

An exception of type 'System.ArgumentException' occurred in Weather.DLL but was not handled in user code

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.

As far as I know, Windows.Foundation.Uri isn't used in the .net framework.

So why is it giving me this error?


回答1:


In XAML:

    <Image Width="250" Height="250" Stretch="UniformToFill">
        <Image.Source>
           <BitmapImage UriSource="{Binding ImagePath}" DecodePixelHeight="250"/>
        </Image.Source>
    </Image>

In C#:

    BitmapImage bitmapImage = BitmapImage("URL HERE");
    bitmapImage.DecodePixelHeight = 250;

Only set DecodePixelHeight or DecodePixelWidth.

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.decodepixelheight.aspx




回答2:


I ended up creating a second, smaller image and using it in all the places where I needed to scale it down.




回答3:


You might be able to avoid the problem you're running into entirely by using the built-in support for image scaling:

http://msdn.microsoft.com/en-us/library/windows/apps/hh465362.aspx

You can include multiple versions of your images at different resolutions (same filename but either with a known suffix or in a known folder), and the system will automatically load the appropriate one for the DPI of the user's device.



来源:https://stackoverflow.com/questions/12949595/high-quality-image-scaling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!