IsolatedStorageFileStream
我的WP7 项目中有一个非常奇怪的问题。我总是收到类似“ Operation not allowed on IsolatedStorageFileStream ”的错误。
这是我的代码(2个案例):
1º:
void camera_Completed(object sender, PhotoResult e)
{
var imageBytes = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(imageBytes, 0, imageBytes.Length);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!myIsolatedStorage.DirectoryExists("Fotos"))
myIsolatedStorage.CreateDirectory("Fotos");
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("foto." + DateTime.Now.Date + "jpeg");
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
e.ChosenPhoto.Seek(0, SeekOrigin.Begin);
imgField.Source = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
thumbnail = imageBytes;
base64String = System.Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
}
2º:
void camera_Completed(object sender, PhotoResult e)
{
var imageBytes = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(imageBytes, 0, imageBytes.Length);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!myIsolatedStorage.DirectoryExists("Fotos"))
myIsolatedStorage.CreateDirectory("Fotos");
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(@"Shared/foto." + DateTime.Now.Date + "jpeg", FileMode.CreateNew, myIsolatedStorage);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
e.ChosenPhoto.Seek(0, SeekOrigin.Begin);
imgField.Source = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
thumbnail = imageBytes;
base64String = System.Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
}
谁能告诉为什么此代码不起作用,并且该站点的示例有效: http: //www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Captured-图片?