Windows phone 访问Windows Phone上保存的图像
我正在为Windows Phone创建照相应用程序,但当我想以Windows phone 访问Windows Phone上保存的图像,windows-phone,Windows Phone,我正在为Windows Phone创建照相应用程序,但当我想以位图图像的形式检索保存的照片时,似乎什么都不起作用。我正在使用IsolatedStorageSettings保存图像的路径,如下所示: Picture p = mediaLibrary.SavePictureToCameraRoll(fileName, e.ImageStream); if (!settings.Contains("lastImageTaken"))
位图图像
的形式检索保存的照片时,似乎什么都不起作用。我正在使用IsolatedStorageSettings
保存图像的路径,如下所示:
Picture p = mediaLibrary.SavePictureToCameraRoll(fileName, e.ImageStream);
if (!settings.Contains("lastImageTaken"))
{
//GetPath() requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
settings.Add("lastImageTaken", p.GetPath());
}
else
{
settings["lastImageTaken"] = p.GetPath();
}
settings.Save();
lastImageTaken = IsolatedStorageSettings.ApplicationSettings["lastImageTaken"] as string;
Uri uri = new System.Uri(lastImageTaken, UriKind.RelativeOrAbsolute);
BitmapImage image = new BitmapImage(uri);
previouseImage.Source = image;
if (image.PixelWidth < 1)
debugText.Text += " FAILED";
然后,一旦应用程序启动,我会尝试检索最后拍摄的照片,如下所示:
Picture p = mediaLibrary.SavePictureToCameraRoll(fileName, e.ImageStream);
if (!settings.Contains("lastImageTaken"))
{
//GetPath() requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
settings.Add("lastImageTaken", p.GetPath());
}
else
{
settings["lastImageTaken"] = p.GetPath();
}
settings.Save();
lastImageTaken = IsolatedStorageSettings.ApplicationSettings["lastImageTaken"] as string;
Uri uri = new System.Uri(lastImageTaken, UriKind.RelativeOrAbsolute);
BitmapImage image = new BitmapImage(uri);
previouseImage.Source = image;
if (image.PixelWidth < 1)
debugText.Text += " FAILED";
但似乎没有任何东西显示图像。to图像的宽度始终显示为0
,在调试文本上显示“FAILED”
文本lastmagetaked
显示为C:\Data\Users\Public\Camera Roll\SMCA\u jpg.jpg
我还添加了
ID\u CAP\u MEDIALIB\u PHOTO
的功能,似乎您正在将图像保存到CameraRoll,但尝试从隔离存储中检索图像。这是两个不同的存储区域,访问方式也不同
为了将图像保存到IsolatedStorage,您需要替换以下内容:
library.SavePictureToCameraRoll(fileName, e.ImageStream);
为此:
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the image to the local folder.
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
然后以与原始帖子中描述的相同方式访问图像。
来源:你能用一些工具检查一下你的图像是否真的保存在独立的存储中吗?我正在保存到camera rollHi!我非常感谢你的回答,但实际上我打算保存到相机卷以及从相机卷中检索。我需要调查一下。我感谢你指出其中的区别!我想您可以从CameraRoll检索的PictureCollection中选择一张图片,这可能会有所帮助: