ハードコードのファイル名だけが機能する理由がわかりませんでしたか?
1) filename をハードコーディングせずに。問題: IsolatedStorageFileStream で許可されていない操作
2) しかし、SaveImageFile() と GetImageInISO() で「Test.jpg」のようにファイル名をハードコーディングすると、
画像を表示でき、エラー メッセージは表示されません。
1 ---------- ImageControl から画像を保存します。
プライベート void SaveImageFile()
{
文字列 strImgFile = strCountry + strCity + ".jpg";
使用 (IsolatedStorageFile ストア = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(strImgFile, FileMode.Create, store))
{
WriteableBitmap wb = new WriteableBitmap(g_IntWidth, g_IntHeight);
wb.Render(cn, new TranslateTransform());
wb.Invalidate();
System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isfs, g_IntWidth, g_IntHeight, 0, 100);
isfs.Close();
}
}
}
--2------------画像を読む
プライベート ボイド GetImageInISO()
{
string strPassIn = strCountryName + strCityName + ".jpg";
BitmapImage bmp = new BitmapImage();
使用 (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
(IsolatedStorageFileStream isfs = store.OpenFile(strPassIn, System.IO.FileMode.Open,FileAccess.Read)) を使用して
{
もし (isfs.Length > 0)
{
bmp.SetSource(isfs);
isfs.Close();
}
そうしないと
{
MessageBox.Show("空のファイル");
}
}
}
image1.Width = bmp.PixelWidth;
image1.Height = bmp.PixelHeight;
image1.Source = bmp;
}
}