我正在为Windows手机开发应用程序,我正在截取屏幕截图,所有这些屏幕截图都保存在媒体库中,现在我的目标是从媒体库中检索所有图像并通过单击按钮逐个显示在ImageBox中,请帮助我该怎么做。 提前谢谢。
答案 0 :(得分:0)
您可以从MediaLibrary
检索照片,然后将其保存到Isolated Storage
,或者按照您的说法将其显示在image
控件中。
private void Pick_Click(object sender, RoutedEventArgs e)
{
var pc = new PhotoChooserTask();
pc.Completed += pc_Completed;
pc.Show();
}
void pc_Completed(object sender, PhotoResult e)
{
var originalFilename = Path.GetFileName(e.OriginalFileName);
SaveImage(e.ChosenPhoto, originalFilename, 0, 100);
}
public static void SaveImage(Stream imageStream, string fileName, int orientation, int quality)
{
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isolatedStorage.FileExists(fileName))
isolatedStorage.DeleteFile(fileName);
var fileStream = isolatedStorage.CreateFile(fileName);
var bitmap = new BitmapImage();
bitmap.SetSource(imageStream);
var wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality);
fileStream.Close();
}
}
希望它有所帮助!