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-画像?