在Windows Phone 7中将图像从媒体库显示到图像框

时间:2014-07-11 06:14:21

标签: windows-phone-7

我正在为Windows手机开发应用程序,我正在截取屏幕截图,所有这些屏幕截图都保存在媒体库中,现在我的目标是从媒体库中检索所有图像并通过单击按钮逐个显示在ImageBox中,请帮助我该怎么做。 提前谢谢。

1 个答案:

答案 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();
    }
}

您也可以在这里查看:How to copy the selected image from picture library to the images folder dynamically in the application?

希望它有所帮助!