/// <summary>
 /// 将实体类改变为ViewModel类.
 /// </summary>
 public static ComposePhotoViewModel CreateFromModel(Photo model)
 {
     ComposePhotoViewModel viewModel = new ComposePhotoViewModel()
     {
         Name = model.Name,
         MediaStream = model.ThumbnailStream,
         PhotoDuration = (int)(model.PhotoDuration.TotalSeconds)
     };
     if (model.Transition != null)
     {
         viewModel.Transition = model.Transition;
         viewModel.TransitionDuration = (int)(model.Transition.TransitionDuration.TotalSeconds);
     }
     return viewModel;
 }
示例#2
0
        /// <summary>
        /// 读取指定的story.
        /// </summary>
        /// <param name="storyName">story名称.</param>
        /// <param name="userStore">如果参数为null, 创建一个新的.</param>
        internal static void ReadStoryFile(string storyName, IsolatedStorageFile userStore = null)
        {
            if (userStore == null)
            {
                userStore = IsolatedStorageFile.GetUserStoreForApplication();
            }
            using (IsolatedStorageFileStream fileStream = userStore.OpenFile(storyName + ".xml", System.IO.FileMode.Open))
            {
                XDocument xdoc = XDocument.Load(fileStream);
                var picturesLibrary = new MediaLibrary().Pictures;

                // Load all photos.
                foreach (XElement photoElement in xdoc.Root.Elements())
                {
                    try
                    {
                        Photo photo = new Photo()
                        {
                            Name = photoElement.Attribute("Name").Value,
                        };
                        string photoDurationString = photoElement.Attribute("PhotoDuration").Value;
                        int photoDuration = int.Parse(photoDurationString);
                        photo.PhotoDuration = TimeSpan.FromSeconds(photoDuration);
                        XElement transitionElement = photoElement.Element("Transition");
                        if (transitionElement != null)
                        {
                            photo.Transition = TransitionBase.Load(photoElement.Element("Transition"));
                        }
                        Picture picture = picturesLibrary.Where(p => p.Name == photo.Name).FirstOrDefault();
                        if (picture == null)
                        {
                            // 如果找不到原文件,可能已经被删除了
                            // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                            continue;
                        }
                        photo.ThumbnailStream = picture.GetThumbnail();
                        App.MediaCollection.Add(photo);
                    }
                    catch
                    {
                        // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                        continue;
                    }
                }
            }
        }
        private void OKButton_Click(object sender, System.EventArgs e)
        {
            this.StoreSelection();

            // 添加所有选中的图片到App.MediaCollection.
            foreach (ChoosePhotoViewModel photo in this._selectedPhotos)
            {
                Photo photoModel = new Photo()
                {
                    Name = photo.Name,
                    ThumbnailStream = photo.MediaStream,
                    PhotoDuration = TimeSpan.FromSeconds(5d),
                    Transition = TransitionFactory.CreateDefaultTransition()
                };
                if (!App.MediaCollection.Contains(photoModel))
                {
                    App.MediaCollection.Add(photoModel);
                }
            }

            // 回到调用页面
            this.NavigationService.GoBack();
        }
示例#4
0
 /// <summary>
 /// 从XNA媒体库中获取的原始图像。
 /// 并调整其大小的目标分辨率。
 /// 调用BitmapHelper.GetResizedImage内部。
 /// 不同的是此方法返回WriteableBitmap的,
 /// 而BitmapHelper.GetResizedImage返回流。
 /// 此方法还设置Photo.ResizedImage和Photo.ResizedImageStream。
 /// </summary>
 /// <param name="photo">图片需要被重设.</param>
 /// <returns>一个WriteableBitmap图片需要被重新设置.</returns>
 private WriteableBitmap GetResizedImage(Photo photo)
 {
     Stream resizedImageStream = BitmapHelper.GetResizedImage(photo.Name);
     WriteableBitmap resizedImage = new WriteableBitmap(BitmapHelper.ResizedImageWidth, BitmapHelper.ResizedImageHeight);
     resizedImage.SetSource(resizedImageStream);
     photo.ResizedImageStream = resizedImageStream;
     photo.ResizedImage = resizedImage;
     return resizedImage;
 }