Comment prendre une image bitmap et l’enregistrer en tant que fichier image JPEG sur un appareil Windows Phone 7?

Je cherche à créer une fonction qui prend une BitmapImage et l’enregistre au format JPEG sur le périphérique Windows Phone 7 local dans un stockage isolé:

 static public void saveImageLocally(ssortingng barcode, BitmapImage anImage) { // save anImage as a JPEG on the device here } 

Comment puis-je accomplir cela? Je suppose que j’ai utilisé IsolatedStorageFile quelque sorte?

Merci.

MODIFIER:

Voici ce que j’ai trouvé jusqu’à présent … quelqu’un peut-il confirmer si c’est la bonne façon de procéder?

  static public void saveImageLocally(ssortingng barcode, BitmapImage anImage) { WriteableBitmap wb = new WriteableBitmap(anImage); using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fs = isf.CreateFile(barcode + ".jpg")) { wb.SaveJpeg(fs, wb.PixelWidth, wb.PixelHeight, 0, 100); } } } static public void deleteImageLocally(ssortingng barcode) { using (IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication()) { MyStore.DeleteFile(barcode + ".jpg"); } } static public BitmapImage getImageWithBarcode(ssortingng barcode) { BitmapImage bi = new BitmapImage(); using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fs = isf.OpenFile(barcode + ".jpg", FileMode.Open)) { bi.SetSource(fs); } } return bi; } 

Pour le sauvegarder:

 var bmp = new WriteableBitmap(bitmapImage); using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = storage.CreateFile(@"MyFolder\file.jpg")) { bmp.SaveJpeg(stream, 200, 100, 0, 95); stream.Close(); } } 

Oui, ce que vous avez ajouté dans votre édition est exactement ce que j’ai fait auparavant 🙂 ça marche.

Ceci est mon code mais vous pouvez prendre les points nécessaires à partir de là:

  var fileName = Ssortingng.Format("{0:}.jpg", DateTime.Now.Ticks); WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap(480, 552); bmpCurrentScreenImage.Render(yourCanvas, new MasortingxTransform()); bmpCurrentScreenImage.Invalidate(); SaveToMediaLibrary(bmpCurrentScreenImage, fileName, 100); public void SaveToMediaLibrary(WriteableBitmap bitmap, ssortingng name, int quality) { using (var stream = new MemoryStream()) { // Save the picture to the Windows Phone media library. bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality); stream.Seek(0, SeekOrigin.Begin); new MediaLibrary().SavePicture(name, stream); } }