任何在WP 8.1中保存调整大小的BitmapImage的方法

时间:2016-04-18 22:41:20

标签: image windows-phone-8.1 image-resizing bitmapimage

如何保存调整大小的BitmapImage?我无法在Windows Phone 8.1中找到这样做的方法。这是我的代码:

BitmapImage bitm = new BitmapImage();
await bitm.SetSourceAsync(stream);

bitm.DecodePixelWidth = 200;
bitm.DecodePixelHeight = 250;

myImage.ImageSource= bitm;

(现在我想存储在一个文件中,因为保存的图像太大了)

1 个答案:

答案 0 :(得分:0)

您可以使用WriteableBitmap保存图像。

    private async void SaveImage(object sender, RoutedEventArgs e)
    {
        BitmapImage bitm = new BitmapImage();
        await bitm.SetSourceAsync(stream);
        bitm.DecodePixelWidth = 200;
        bitm.DecodePixelHeight = 250;
        WriteableBitmap wb = new WriteableBitmap(bitm);
        wb.Invalidate();
        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/hello.jpg", System.IO.FileMode.Create, isf))
            {
                wb.SaveJpeg(imageStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
            }
        }

    }