经验及技巧:windows phone 8.1开发图像编码解码

如何在windows phone 8.1中利用FileSavePicker保存图片.windows phone 8.1图像编码的类是BitmapEncoder,解码的类是BitmapDecoder.关于图像的编码和解码的详细说明请参考msdn文档( http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh465080.aspx   同时在啰唆一句:MSDN真心很强大!大家一定要好好利用!) 使用FileSavePicker保存图片步骤和思路和 FileSavePicker保存文件 基本是一样的,不同之处就是确定保存文件位置再次返回应用的处理.具体处理如下:
private async void ContinuFileSavePicker(FileSavePickerContinuationEventArgs args)
        {
            if (args.ContinuationData["Operation"] as string == "ImageSave" && args.File != null)
            {
                StorageFile imageFile = args.File;
                StorageFile inFile=  await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("3.jpg");
                var inStream = await inFile.OpenAsync(FileAccessMode.Read);//获取要保存的图片的流
                var outStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite);//获取要新建的图片的流
                    outStream.Size = 0;
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(inStream);//建立解码器
                    PixelDataProvider provider = await decoder.GetPixelDataAsync();//获取像素数据
                    byte[] data = provider.DetachPixelData(); //获取像素数据的字节数组
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outStream);//建立编码器
                    encoder.SetPixelData(decoder.BitmapPixelFormat,decoder.BitmapAlphaMode,
                                                       decoder.PixelWidth,decoder.PixelHeight,
                                                       decoder.DpiX,decoder.DpiY,data
                        );//设置要保存的图片的数据  参数依次表示 像素格式,Alpha格式,宽度,高度,水平分辨率,垂直分辨率,要保存的像素数据
 
                    try
                    {
                        await encoder.FlushAsync(); //提交和刷新像素数据
 
                    }
                    catch (Exception err)
                    {
                        Debug.WriteLine(err.ToString());
                    }
                finally
                    {
                        inStream.Dispose(); //释放流
                        outStream.Dispose();//释放流
                    }
 
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值