【发布时间】:2015-07-24 11:25:12
【问题描述】:
我是 Windows Phone 编程的新手!我的问题是如何在 windows phone 8.1 中保存和检索图像到文件中?我已经看到了一些链接,但它们都在 windows phone 7 中。 [http://www.geekchamp.com/tips/all-about-wp7-isolated-storage---read-and-save-images#][1] 我不会这样,但这段代码只能运行到 windows phone 7
// 为独立存储中的 JPEG 文件创建文件名。 字符串 tempJPEG = "logo.jpg";
// Create virtual store and file stream. Check for duplicate tempJPEG files.
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(tempJPEG))
{
myIsolatedStorage.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
StreamResourceInfo sri = null;
Uri uri = new Uri(tempJPEG, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
//wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
【问题讨论】:
标签: image file windows-phone-8.1 isolatedstorage