0

在我的应用程序中,用户使用 PhotoChooserTask 从相机胶卷中选择一张照片。我想将照片的位置保存到 LogEntry 类的字符串变量中,以便稍后根据需要重新加载照片。

Log 是 LogEntry 类项的 ObservableCollection。

public ObservableCollection<LogEntry> Log = new ObservableCollection<LogEntry>();

如果不将照片保存到 LogEntry 中的字节数组中并且不将照片保存到独立存储中,我该如何做到这一点?

4

1 回答 1

0

首先,我将所选图片的名称和专辑的名称保存在我的每个 LogEntry 项目的属性中。

从相册加载图片:

        public BitmapImage GetPicture( string FileName )
        {
        // Work around for known bug in the media framework.  Hits the static constructors
        // so the user does not need to go to the picture hub first.
        MediaPlayer.Queue.ToString();

        MediaLibrary ml = null;
        PictureAlbum cameraRoll = null;
        PictureAlbum savedPictures = null;
        PictureAlbum samplePictures = null;
        PictureAlbum favoritePictures = null;

        int index = FileName.IndexOf( "\\" );
        string albumName = FileName.Remove( index, FileName.Length - index );
        string fileName = FileName.Remove( 0, index + 1 );

        foreach ( MediaSource source in MediaSource.GetAvailableMediaSources() )
            {
            if ( source.MediaSourceType == MediaSourceType.LocalDevice )
                {
                ml = new MediaLibrary( source );
                PictureAlbumCollection allAlbums = ml.RootPictureAlbum.Albums;

                foreach ( PictureAlbum album in allAlbums )
                    {
                    if ( album.Name == "Camera Roll" )
                        {
                        cameraRoll = album;
                        }
                    else if ( album.Name == "Saved Pictures" )
                        {
                        savedPictures = album;
                        }
                    else if ( album.Name == "Sample Pictures" )
                        {
                        samplePictures = album;
                        }
                    else if ( album.Name == "Favorite Pictures" )
                        {
                        favoritePictures = album;
                        }
                    }
                }
            }

        PictureAlbum Album;
        switch ( albumName )
            {
            case "Camera Roll":
                Album = cameraRoll;
                break;

            case "Saved Pictures":
                Album = savedPictures;
                break;

            case "Sample Pictures":
                Album = samplePictures;
                break;

            case "Favorite Pictures":
                Album = favoritePictures;
                break;

            default:
                Album = null;
                break;
            }

        if ( Album == null )
            {
            return new BitmapImage();
            }

        BitmapImage b = new BitmapImage();
        foreach ( Picture p in Album.Pictures.Take( Album.Pictures.Count ) )
            {
            if ( fileName == p.Name )
                {
                b.SetSource( p.GetThumbnail() );
                break;
                }
            }

        return b;
        }
于 2013-05-10T00:09:24.043 回答