我不明白为什么只有硬编码文件名有效?
1)没有硬编码文件名。问题:IsolatedStorageFileStream 上不允许操作
2) 但是当我硬编码文件名时,比如 SaveImageFile() 和 GetImageInISO() 中的“Test.jpg”,
我可以查看图像并且没有错误消息。
1---------- 从 ImageControl 保存图像:
私人无效 SaveImageFile()
{
字符串 strImgFile = strCountry + strCity + ".jpg";
使用(IsolatedStorageFile 存储 = IsolatedStorageFile.GetUserStoreForApplication())
{
使用 (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()
{
字符串 strPassIn = strCountryName + strCityName + ".jpg";
BitmapImage bmp = new BitmapImage();
使用 (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
使用 (IsolatedStorageFileStream isfs = store.OpenFile(strPassIn, System.IO.FileMode.Open,FileAccess.Read))
{
if (isfs.Length > 0)
{
bmp.SetSource(isfs);
isfs.Close();
}
别的
{
MessageBox.Show("空文件");
}
}
}
image1.Width = bmp.PixelWidth;
image1.Height = bmp.PixelHeight;
image1.Source = bmp;
}
}