Created
October 9, 2013 04:19
-
-
Save scorta/6896167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SaveImageClicked(object sender, GestureEventArgs e) | |
{ | |
var webClient = new WebClient(); | |
webClient.OpenReadCompleted += WebClientOpenReadCompleted; | |
webClient.OpenReadAsync(new Uri(IMAGE_URL, UriKind.Absolute)); | |
} | |
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e) | |
{ | |
const string tempJpeg = "TempJPEG"; | |
var streamResourceInfo = new StreamResourceInfo(e.Result, null); | |
var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication(); | |
if (userStoreForApplication.FileExists(tempJpeg)) | |
{ | |
userStoreForApplication.DeleteFile(tempJpeg); | |
} | |
var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg); | |
var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None }; | |
bitmapImage.SetSource(streamResourceInfo.Stream); | |
var writeableBitmap = new WriteableBitmap(bitmapImage); | |
writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85); | |
isolatedStorageFileStream.Close(); | |
isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read); | |
// Save the image to the camera roll or saved pictures album. | |
var mediaLibrary = new MediaLibrary(); | |
// Save the image to the saved pictures album. | |
mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream); | |
isolatedStorageFileStream.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment