2016-06-15 7 views
-1

ギャラリーで見ることができ、後で使用できるイメージとしてStorageFileを保存します。 StorageFileには、カメラで撮影した画像またはギャラリーから撮影した画像が含まれ、StorageFileで変換されます。Windows phone 8.1 save StorageFile as image

+0

あなたの質問はありますか? –

+0

ギャラリーに画像が見えるようにStorageFileファイルを電話に保存するには –

+0

編集した画像を保存するのですか? – Archana

答えて

0
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(); 
     } 
+0

素晴らしいです。しかし、画像がカメラで撮影されると、BitmapImageが取得されます。 BitmapImageをWriteableBitmapに変換するのに、このメソッドを使用していますが、保存されたイメージは完全に黒です。コード: パブリックasync void CreateWriteableBitmap() { WriteableBitmap newImg; var obj = AppとしてのApp.Current; BitmapImage originalPic = obj.ImageToEdit; StorageFileファイル= obj.fileTransfer; newImg = new WriteableBitmap(originalPic.PixelWidth、originalPic.PixelHeight); using(var stream = await file.OpenReadAsync()) {newImg.SetSourceAsync(await)}} –

+0

フィルタやトリミングを適用していますか? – Archana

+0

いいえ、元の未編集の画像です。 –

0

既知の画像拡張子(.jpgや.pngなど)を使用してstoragefileをパブリックフォルダに保存すると、ギャラリーに表示されます。

関連する問題