Windows Phone:如何从应用程序实例之间的媒体库中检索同一张照片
如何在应用程序实例之间从媒体库中检索同一张照片?我启动照片库供用户通过以下方式选择照片:
How do I retrieve the same photo from the media library between application instances? I launch the photo library for the user to select a photo via:
PhotoChooserTask myPhotoChooser = new PhotoChooserTask();
myPhotoChooser.ShowCamera = true;
myPhotoChooser.Show();
myPhotoChooser.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
然后在事件处理程序中,我像这样检索所选文件的文件名:
and then in the Event handler, I retrieve the file name of the selected file like this:
private void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
string imagePath = e.OriginalFileName.ToString();
}
}
我将此信息保存在隔离的存储中,以便当用户再次启动应用程序时,我可以检索路径并显示图像,如下所示:
I persist this information in isolated storage so that when a user launches the application again I can retrieve the path and display the image like this:
private BitmapImage ConvertUriToBitmap(string pathToImage)
{
StreamResourceInfo streamResInfo = null;
Uri uri = new Uri(pathToImage, UriKind.Relative);
streamResInfo = Application.GetResourceStream(uri); //This fails! StreamResInfo is null
BitmapImage convertedBitmap = new BitmapImage();
convertedBitmap.SetSource(streamResInfo.Stream);
return convertedBitmap;
}
但是,这似乎不起作用,因为来自照片选择器的照片路径采用以下形式的引导:"\ Applications \ Data \ 02E58193-119F-42E2-AD85-C24247BE2AB0 \ Data \ PlatformData \ PhotoChooser -4edd185d-d934-4dac-8a34-758cac09d338.jpg"
However, this doesn't seem to work as the photo path from the photo chooser is some sort of guid in the form: "\Applications\Data\02E58193-119F-42E2-AD85-C24247BE2AB0\Data\PlatformData\PhotoChooser-4edd185d-d934-4dac-8a34-758cac09d338.jpg"
Application.GetResourceStream(uri)为null.有更好的方法吗?
Application.GetResourceStream(uri) is null whenenever I switch out of the application or move between pages. Is there a better way to do this?
我如何每次都检索相同的路径,以便当我进行逻辑删除或杀死该应用程序时,我可以收回该文件并显示它?还是有其他/更有效的方式来做到这一点.
How do I retrieve the same path everytime so that when I tombstone or kill the app, i can retireve the file and display it? Or is there a different /more efficient way of doing it.
I found the answer in the documentation: http://msdn.microsoft.com/en-us/library/gg680264%28v=pandp.11%29.aspx Basically, there is a bug in the photo chooser which returns a temporary path. Microsofts recommendation is to copy the picture to isolated storage if you want to use it between app instances.