C# Windows phone 8.1将存储文件另存为映像

C# Windows phone 8.1将存储文件另存为映像,c#,image,file,windows-phone-8.1,save,C#,Image,File,Windows Phone 8.1,Save,我想将StorageFile另存为图像,以便在gallery中查看并在以后使用。StorageFile包含由相机拍摄或从gallery拍摄并在StorageFile中转换的图像。将具有已知图像扩展名(如.jpg或.png)的StorageFile保存在公用文件夹中,它将显示在gallery中。您的问题是什么?如何在手机上保存StorageFile文件,以便在gallery中查看图像?您的意思是保存编辑过的图像?是的。我想将编辑后的图像保存到手机上,编辑后的图像将转换为存储文件,以便使用dataW

我想将StorageFile另存为图像,以便在gallery中查看并在以后使用。StorageFile包含由相机拍摄或从gallery拍摄并在StorageFile中转换的图像。

将具有已知图像扩展名(如.jpg或.png)的StorageFile保存在公用文件夹中,它将显示在gallery中。

您的问题是什么?如何在手机上保存StorageFile文件,以便在gallery中查看图像?您的意思是保存编辑过的图像?是的。我想将编辑后的图像保存到手机上,编辑后的图像将转换为存储文件,以便使用dataWorks进行更轻松的操作。但当用相机拍摄图像时,我会得到位图图像。我正在使用此方法将位图图像转换为可写位图,但保存的图像为全黑色。代码:public async void createablebitmap(){WriteableBitmap newImg;var obj=App.Current as App;BitmapImage originalPic=obj.ImageToEdit;StorageFile=obj.fileTransfer;newImg=new WriteableBitmap(originalPic.PixelWidth,originalPic.PixelHeight);使用(var stream=await file.OpenReadAsync()){await newImg.SetSourceAsync(stream)}是否应用任何筛选或裁剪?返回任务
public异步任务CreateWriteableBitmap(){..}
并在调用方法
await CreateWriteableBitmap()
private async void SaveCroppedImage(object sender, RoutedEventArgs e)
       {
           StorageFile file = await KnownFolders.CameraRoll.CreateFileAsync("edited.jpg", CreationCollisionOption.ReplaceExisting);
           using (IRandomAccessStream stream =await file.OpenAsync(FileAccessMode.ReadWrite))
           {
               await EncodeWriteableBitmap(WB_CroppedImage, stream, BitmapEncoder.JpegEncoderId);
           }

       }
       private static async Task EncodeWriteableBitmap(WriteableBitmap bmp, IRandomAccessStream writeStream, Guid encoderId)
       {
           // Copy buffer to pixels
           byte[] pixels;
           using (var stream = bmp.PixelBuffer.AsStream())
           {
               pixels = new byte[(uint)stream.Length];
               await stream.ReadAsync(pixels, 0, pixels.Length);
           }
           // Encode pixels into stream
           var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
           encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied,
              (uint)bmp.PixelWidth, (uint)bmp.PixelHeight,
              96, 96, pixels);
           await encoder.FlushAsync();
       }