使用FileSavePicker在Windows Phone 8.1中保存图像

我想使用文件保存选择器保存图像。 我正在使用此链接保存,但它仅用于文本,我如何修改它以保存图像?

由于您提供了链接,因此我假设您在Continuation之后设法获得了StorageFile (这是它在WP8.1运行时的工作方式)。

我还假设您的图像有一个Stream ,或者您知道如何获得这样的图像。 基于这两个,您可以将图像以png格式保存到选择器选择的文件中,例如:

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 (和其他资源)。

如果您看一下BitmapEncoder和BitmapDecoder类,那么您将看到更多选项,包括转换和各种属性。

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