Windows phone 8 使用PhotoChooserTask wp8获取照片文件Uri
对于我当前的项目,我有一个IEnumerable属性ImageCollection,如下所示Windows phone 8 使用PhotoChooserTask wp8获取照片文件Uri,windows-phone-8,isolatedstorage,cameracapturetask,Windows Phone 8,Isolatedstorage,Cameracapturetask,对于我当前的项目,我有一个IEnumerable属性ImageCollection,如下所示 public static IEnumerable<Uri> ImageCollection { get; set; } 但是,我希望将引用Uri或e.OriginalFileName存储在数据库中。我了解到,即使将副本存储在单独的存储中,我也无法实现我所寻找的目标-使用photoChooserTask获取所选文件的引用。我可能错了 尽管我最初的想法是将Gallery文件的Uri添
public static IEnumerable<Uri> ImageCollection { get; set; }
但是,我希望将引用Uri或e.OriginalFileName存储在数据库中。我了解到,即使将副本存储在单独的存储中,我也无法实现我所寻找的目标-使用photoChooserTask获取所选文件的引用。我可能错了
尽管我最初的想法是将Gallery文件的Uri添加到我的ImageCollection中,并将每个项目的索引存储在数据库中,但任何建议或即兴创作都是非常感谢的
注意:添加的CameraCaptureTask标记作为PhotoChooserTask标记不可用,基本逻辑相同
编辑用于存储和检索IsolatedStorage的代码
我正在将GetImageFromIsolatedStorage方法的结果绑定到我的图像控制源。这不管用。。我做错了什么
public static string SaveImageToIsolatedStorage(BitmapImage bitImg)
{
string fname = null;
if (bitImg != null)
{
fname = GetImageName();
WriteableBitmap wbmp = new WriteableBitmap(bitImg);
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
using (isf)
{
if (isf.FileExists(fname)) { isf.DeleteFile(fname); }
using (var stream = isf.OpenFile(fname, System.IO.FileMode.OpenOrCreate))
{
wbmp.SaveJpeg(stream, bitImg.PixelWidth, bitImg.PixelHeight, 0, 100);
stream.Close();
}
}
}
return fname;
}
private static string GetImageName()
{
return string.Format(
"{0}/GalleryImage{1}.jpg",
FileDir,
ImageCount++);
}
public static BitmapImage GetImageFromIsolatedStorage(string fname)
{
BitmapImage img = new BitmapImage();
try
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = isf.OpenFile(fname, FileMode.Open, FileAccess.Read))
{
img.SetSource(fileStream);
fileStream.Close();
}
}
}
catch { }
return img;
}
这是不可能的。在Windows Phone中,选择任务和完全访问设备库是两件不同的事情
您可以指定应用程序完全访问库并以这种方式进行处理,或者使用ChooserTask,让用户选择照片,也可以裁剪照片,然后将此图像保存到应用程序的独立存储中 即使我将图像存储到电话隔离存储中,我也不能通过Uri引用它,是吗?我指的是线程按照您的建议继续。如果您将图像保存到隔离存储中,那么可以通过Uri引用ib。因为你的应用程序可以完全访问隔离存储。你能给我一些工作示例吗?我可以保存它,但无法使用Uri读回它。已经更新了我正在尝试的代码…您只需使用以下命令获取图像,而不是调用方法:new Uriisostore:/[yourFolder]/gallerymage2.png,UriKind.Absolute;
public static string SaveImageToIsolatedStorage(BitmapImage bitImg)
{
string fname = null;
if (bitImg != null)
{
fname = GetImageName();
WriteableBitmap wbmp = new WriteableBitmap(bitImg);
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
using (isf)
{
if (isf.FileExists(fname)) { isf.DeleteFile(fname); }
using (var stream = isf.OpenFile(fname, System.IO.FileMode.OpenOrCreate))
{
wbmp.SaveJpeg(stream, bitImg.PixelWidth, bitImg.PixelHeight, 0, 100);
stream.Close();
}
}
}
return fname;
}
private static string GetImageName()
{
return string.Format(
"{0}/GalleryImage{1}.jpg",
FileDir,
ImageCount++);
}
public static BitmapImage GetImageFromIsolatedStorage(string fname)
{
BitmapImage img = new BitmapImage();
try
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = isf.OpenFile(fname, FileMode.Open, FileAccess.Read))
{
img.SetSource(fileStream);
fileStream.Close();
}
}
}
catch { }
return img;
}