如何将独立存储中的图像加载到 Windows 手机上的图像控件中? [英] How to load an image from isolated storage into image control on windows phone?
本文介绍了如何将独立存储中的图像加载到 Windows 手机上的图像控件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码在相机动作完成时将图像存储到隔离存储中.
I am using this code for storing the image into isolate storage at the time of camera action completed.
void camera_Completed(object sender, PhotoResult e)
{
BitmapImage objImage = new BitmapImage();
//objImage.SetSource(e.ChosenPhoto);
//Own_Image.Source = objImage;
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
fnam = e.OriginalFileName.Substring(93);
MessageBox.Show(fnam);
if (isolatedStorage.FileExists(fnam))
isolatedStorage.DeleteFile(fnam);
IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(fnam);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 100, 100);
MessageBox.Show("File Created");
fileStream.Close();
}
}
现在我想从独立存储中获取图像并将其显示在我的图像控件中.
Now I want to take the image from isolated storage and display it in my image control.
有可能吗?
推荐答案
是的.您可以使用此函数从隔离存储加载图像:
Yes it is. You can use this function to load image from IsolatedStorage:
private static BitmapImage GetImageFromIsolatedStorage(string imageName)
{
var bimg = new BitmapImage();
using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = iso.OpenFile(imageName, FileMode.Open, FileAccess.Read))
{
bimg.SetSource(stream);
}
}
return bimg;
}
用法:
ImageControl.Source = GetImageFromIsolatedStorage(fnam);
这篇关于如何将独立存储中的图像加载到 Windows 手机上的图像控件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文