我有一些问题要从媒体库中获取图像,我想知道是否有任何选项可以获取或自动过滤库中的某些图像。 例如,假设我有像1.jpg,2.jpg,3.jpg ........等图像。我从媒体库获取图像并将所有图像保存在隔离存储中,所以我想只获取某些图像,而不是所有来自媒体库的图像,这是我的代码
using (MediaLibrary mediaLibrary = new MediaLibrary())
{
PictureCollection AllScreenShot = mediaLibrary.Pictures;
foreach (Picture picture in AllScreenShot)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.DirectoryExists("SavedImg"))
storage.CreateDirectory("SavedImg");
if (storage.FileExists("SavedImg" + "\\" + picture.Name))
storage.DeleteFile("SavedImg" + "\\" + picture.Name);
using (IsolatedStorageFileStream file = storage.CreateFile("SavedImg" + "\\" + picture.Name))
picture.GetImage().CopyTo(file);
}
}
}
答案 0 :(得分:1)
这将有助于
var picture = media.Pictures.FirstOrLast(p => p.Name.Contains("1.jpg"));
if (picture == null)
{
// 1.jpg not found
}
else
{
//1.jpg found
}