문제

I've got a bunch of (very) large images in my application. For them to fit into my ImageView and the corresponding Image control, I'm using the following XAML:

<Image Name="imageEdit" Stretch="Uniform" />

Now this works marvelously when using large images, as they're automatically scaled down. However, when displaying small images they're being scaled higher and thus become blurry.

Is there a way I can prevent that from happening and only have those images resizes, that would otherwise actually reach behind the boundaries of the Image control?

도움이 되었습니까?

해결책

In WPF there is a property just for this reason called StretchDirection, setting it to DownOnly does exactly what you'd like to achieve.

다른 팁

You could bind the image size (dimensions) to the Stretch property through a converter.

Then in the converter return Stretch.None if the image size is less than or equal to the space available and Stretch.Uniform if it's larger. For example (just checking the X dimension):

public class SizeToStretchConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (int)value <= targetWidth ? Stretch.None : Stretch.Uniform;
    }

    public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

As a workaround, you may want to try setting BitmapScalingMode.

Also take a look at this SO question discussing blurry WPF images.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top