如何在Windows Phone 8应用程序中调整图像大小?

时间:2014-07-23 14:29:48

标签: image windows-phone-8 writeablebitmapex

如何在不损失质量的情况下使用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;
    }

}

原始图片 图像的实际大小为38 MB,Dimention 10240x6400,高度:10240,宽度:6400

我得到的结果是在图像下面

enter image description here

0 个答案:

没有答案