如何在Windows Phone 8.1应用程序中的文件/文件夹目录中保存位图图像

时间:2014-10-04 18:08:54

标签: c# bitmap windows-phone-8.1

我想在我的应用程序中保存我的文件夹名称照片中的图像。我使用FilePicker选择一个图像文件并在按钮上单击图像控件中显示我想将其保存在目录中。我该怎么做。我可以已经执行保存图片库但无法保存在文件夹中。任何人都可以提供示例代码吗?

 RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
       await renderTargetBitmap.RenderAsync(MyCanvas);
       //StorageFile saveFile = await KnownFolders.PicturesLibrary.GetFileAsync("sample.jpg");
       StorageFolder storageFolder = KnownFolders.PicturesLibrary;
      StorageFile sampleFile = await storageFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);

       var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();


       using (var fileStream = await sampleFile.OpenAsync(FileAccessMode.ReadWrite))
       {
           var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

           encoder.SetPixelData(
               BitmapPixelFormat.Bgra8,
               BitmapAlphaMode.Ignore,
               (uint)renderTargetBitmap.PixelWidth,
               (uint)renderTargetBitmap.PixelHeight,
               DisplayInformation.GetForCurrentView().LogicalDpi,
               DisplayInformation.GetForCurrentView().LogicalDpi,
               pixelBuffer.ToArray());

           await encoder.FlushAsync();

0 个答案:

没有答案