保存图像使用FileSavePicker的Windows Phone 8.1 [英] Save image in windows phone 8.1 using FileSavePicker

查看:120
本文介绍了保存图像使用FileSavePicker的Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用文件保存选取器来保存图像。我使用的链接保存,但它仅适用于文本,我怎么修改保存图像

I want to save an image using File Save Picker . I am using this link to save but it is only for text , how I modify it to save an image?

推荐答案

正如你所提供的的链接那么我认为你设法获得的 StorageFile 延续后(这是怎么了在WP8.1运行时有效)。

As you have provided the link then I assume that you managed to get StorageFile after Continuation (this is how it works at WP8.1 Runtime).

我也假设你有一个的的与你的图像或你知道如何获得这样的人。立足于这两个,你可以保存你的图像中的 PNG 的格式通过选择器例如选择这样的文件:

I also assume that you have a Stream with your image or you know how to obtain such a one. Basing on those two, you can save your image in png format to a file selected by picker for example like this:

public async Task SaveStreamAsync(IRandomAccessStream streamToSave, StorageFile destination)
{
    BitmapDecoder bmpDecoder = await BitmapDecoder.CreateAsync(streamToSave);
    PixelDataProvider pixelData = await bmpDecoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, null, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage);
    using (var destFileStream = await destination.OpenAsync(FileAccessMode.ReadWrite))
    {
        BitmapEncoder bmpEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destFileStream);
        uint yourWidthAndOrHeight = 1024;
        bmpEncoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, yourWidthAndOrHeight, yourWidthAndOrHeight, 300, 300, pixelData.DetachPixelData());
        await bmpEncoder.FlushAsync();
    }
}



也请记得处置你的 streamToSave (和其他资源)完成与他们一起工作了。

Also please remember to Dispose your streamToSave (and other resources) after finishing working with them.

如果您看看的BitmapEncoder 并的 BitmapDecoder 类,然后你会看到更多的选项,包括转型各种属性。

If you take a look at BitmapEncoder and BitmapDecoder classes, then you will see more options including transformation and various properties.

(我没有测试上面粗糙的代码,但希望它会正常工作)

(I've not tested the code above rough, but hopefully it will work fine)

这篇关于保存图像使用FileSavePicker的Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆