UWP bitmap smoothing

I am trying to figure out how to resize an image without losing quality in UWP. I know that in WPF there is an opportunity to smooth the image using this: RenderOptions.BitmapScalingMode="HighQuality"but I cannot find the equivalent in UWP.

This is what the image looks like:

And how it should look:

If you look carefully, you will see that the image is poorly pixelated. How can I achieve this in UWP?

I am resizing it using XAML (circle cropping):

<Ellipse x:Name="personImageContainer" Width="50" Height="50">
    <Ellipse.Fill>
        <ImageBrush x:Name="personImage" ImageSource="/Assets/BlankContact.png" Stretch="Uniform" />
    </Ellipse.Fill>
</Ellipse>

and just set the image as follows:

personImage.ImageSource = new BitmapImage(new Uri("http://lorempixel.com/500/500/"));

I can not find any other settings in ImageBrushand BitmapImagethat do this.

+4
source share
1 answer

, Image, , , , Image . , GPU , , , , .

, , , ImageBrush Ellipse, . ( .)

Ellipse , , ​​ .

<!-- Bad: image will be full resolution -->
<Ellipse Width="50" Height="50">
    <Ellipse.Fill>
        <ImageBrush Stretch="UniformToFill" ImageSource="Assets/Cat.jpg"/>
    </Ellipse.Fill>
</Ellipse>

<!-- Better: image is scaled down nicely and uses less memory -->
<Ellipse Width="50" Height="50">
    <Ellipse.Fill>
        <ImageBrush Stretch="UniformToFill">
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="Assets/Cat.jpg" DecodePixelType="Logical" DecodePixelWidth="50"/>
            </ImageBrush.ImageSource>
        </ImageBrush>
    </Ellipse.Fill>
</Ellipse>

Screenshot

.

+6

Source: https://habr.com/ru/post/1658145/


All Articles