2

如何在不损失质量的情况下使用 C# 在 windows phone 8.0 应用程序中调整图像大小并显示完整图像

我做了什么,

我的 XAML 代码:

<StackPanel Orientation="Vertical">
    <TextBlock Text="Select Image" FontSize="45" Height="106"></TextBlock>
    <Image Name="ImgPrev" Height="455" Stretch="None" ></Image>
</StackPanel>

我的 C# 代码

public MainPage()
{

    InitializeComponent();

    // Sample code to localize the ApplicationBar
    //BuildLocalizedApplicationBar();

    BitmapImage image = new BitmapImage();
    image.SetSource(Application.GetResourceStream(new Uri(@"Assets/Bug.jpg", UriKind.Relative)).Stream);
    image.DecodePixelType = DecodePixelType.Logical;
    image.CreateOptions = BitmapCreateOptions.BackgroundCreation;
    image.CreateOptions = BitmapCreateOptions.DelayCreation;
    Image img = new Image();
    img.Source = image;
    WriteableBitmap wb = new WriteableBitmap(image);
    wb.Resize(1000, 1000, WriteableBitmapExtensions.Interpolation.Bilinear);
    using(MemoryStream stream=new MemoryStream())
    {
        wb.SaveJpeg(stream, 1000, 1000, 0, 100);
        BitmapImage resize = new BitmapImage();
        resize.SetSource(stream);
        ImgPrev.Source = resize;
    }

}

原图图片实际大小为38MB,尺寸10240x6400,高:10240,宽:6400

我得到的结果如下图

在此处输入图像描述

4

0 回答 0