public void Add(PhotoFile file) { if (File1 == null) { File1 = file; } else if (File2 == null) { File2 = file; } else if (File3 == null) { File3 = file; } }
private void MakePhotoAlbum(PictureAlbum album) { PhotoRow currentRow = null; var stopwatch = Stopwatch.StartNew(); var photoFiles = new List <PhotoFile>(); var photoRow = new ObservableCollection <PhotoRow>(); var secondSlice = new List <PhotoFile>(); _album = album; if (_album.Pictures.Count > 0) { var cropedFiles = _album.Pictures.OrderByDescending(x => x.Date).ToList(); var maxCount = 12; for (var i = 0; i < cropedFiles.Count; i++) { var p = cropedFiles[i]; var photoFile = new PhotoFile { Picture = p, SuppressAnimation = true, IsSelected = _selectedPictures.ContainsKey(p) }; if (i < maxCount) { if (i % 3 == 0) { currentRow = new PhotoRow(); photoRow.Add(currentRow); } Stream thumbnail; try { thumbnail = p.GetThumbnail(); } catch (Exception e) { Log.Write(string.Format("OpenPhotoPicker File getThumbnail exception album={0} file={1}\n{2}", album.Name, p.Name, e)); cropedFiles.RemoveAt(i--); continue; } photoFile.IsForeground = true; photoFile.Thumbnail = new WeakReference <Stream>(thumbnail); photoFiles.Add(photoFile); currentRow.Add(photoFile); photoFile.Row = currentRow; } else { secondSlice.Add(photoFile); } } } System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => { CurrentAlbum = album; if (photoRow.Count < 4) { Photos.VerticalAlignment = VerticalAlignment.Bottom; } else { Photos.VerticalAlignment = VerticalAlignment.Stretch; } Photos.ItemsSource = photoRow; //LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)); Photos.Visibility = Visibility.Visible; Photos.Opacity = 0.0; Telegram.Api.Helpers.Execute.BeginOnUIThread(() => { Photos.Opacity = 1.0; var storyboard = new Storyboard(); var translateAnimaiton = new DoubleAnimationUsingKeyFrames(); translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0.0), Value = Photos.ActualHeight }); translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0.4), Value = 0.0, EasingFunction = new ExponentialEase { Exponent = 5.0, EasingMode = EasingMode.EaseOut } }); Storyboard.SetTarget(translateAnimaiton, Photos); Storyboard.SetTargetProperty(translateAnimaiton, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); storyboard.Children.Add(translateAnimaiton); storyboard.Begin(); if (secondSlice.Count > 0) { storyboard.Completed += (o, e) => { for (var i = 0; i < secondSlice.Count; i++) { if (i % 3 == 0) { currentRow = new PhotoRow(); photoRow.Add(currentRow); } photoFiles.Add(secondSlice[i]); currentRow.Add(secondSlice[i]); secondSlice[i].Row = currentRow; } }; } }); }); }
private void ChangePictureSelection(PhotoFile file1, bool isSelected) { var index = 0; // select middle item first of all if (!IsSingleItem && _hasManipulatingDelta && _previousFile != null && _previousFile.Row == file1.Row && file1.Row.File2.IsSelected != isSelected) { var row = file1.Row; if ( (row.File1 == _previousFile && row.File3 == file1) || (row.File3 == _previousFile && row.File1 == file1)) { if (isSelected) { _selectedPictures[row.File2.Picture] = row.File2; index = _selectedPictures.Count; } else { _selectedPictures.Remove(row.File2.Picture); foreach (var photoFile in _selectedPictures.Values) { if (photoFile.Index > row.File2.Index) { photoFile.Index--; photoFile.RaisePropertyChanged("Index"); } } index = 0; } row.File2.SuppressAnimation = false; row.File2.IsSelected = isSelected; row.File2.RaisePropertyChanged("IsSelected"); row.File2.Index = index; row.File2.RaisePropertyChanged("Index"); } } if (isSelected) { _selectedPictures[file1.Picture] = file1; index = _selectedPictures.Count; } else { _selectedPictures.Remove(file1.Picture); foreach (var photoFile in _selectedPictures.Values) { if (photoFile.Index > file1.Index) { photoFile.Index--; photoFile.RaisePropertyChanged("Index"); } } index = 0; } file1.SuppressAnimation = false; file1.IsSelected = isSelected; file1.RaisePropertyChanged("IsSelected"); file1.Index = index; file1.RaisePropertyChanged("Index"); _previousFile = file1; _selectButton.IsEnabled = _selectedPictures.Any(); if (IsSingleItem) { ChooseButton_OnClick(null, null); LayoutRoot.IsHitTestVisible = false; } }
public async void SetFile(StorageFile result, PhotoFile file) { if (result == null) { return; } _result = result; var properties = await result.Properties.GetImagePropertiesAsync(); if (properties != null && properties.Width > 0 && properties.Height > 0) { _width = properties.Width; _height = properties.Height; if (_width == 0 || _height == 0) { return; } var minDimension = Math.Min(_width, _height); ImageBorder.Width = _width * 400.0 / minDimension; ImageBorder.Height = _height * 400.0 / minDimension; ImageBorder.Margin = new Thickness((400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0, (400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0); _stopwatch = Stopwatch.StartNew(); var stream = await result.GetThumbnailAsync(ThumbnailMode.SingleItem, 800); System.Diagnostics.Debug.WriteLine("Picture.OpenReadAsync=" + _stopwatch.Elapsed); var thumbnailSource = new BitmapImage(); //thumbnailSource.DecodePixelHeight = (int) ImageBorder.Height * 3; //thumbnailSource.DecodePixelWidth = (int) ImageBorder.Width * 3; thumbnailSource.CreateOptions = BitmapCreateOptions.BackgroundCreation; thumbnailSource.SetSource(stream.AsStream()); Image.Source = thumbnailSource; } else { var sourceStream = await result.OpenReadAsync(); var decoder = await BitmapDecoder.CreateAsync(sourceStream); _width = decoder.OrientedPixelWidth; _height = decoder.OrientedPixelHeight; if (_width == 0 || _height == 0) { return; } var minDimension = Math.Min(_width, _height); ImageBorder.Width = _width * 400.0 / minDimension; ImageBorder.Height = _height * 400.0 / minDimension; ImageBorder.Margin = new Thickness((400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0, (400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0); _stopwatch = Stopwatch.StartNew(); var resizedJpeg = await DialogDetailsViewModel.ResizeJpeg(sourceStream, 800, string.Empty, string.Empty); var stream = new MemoryStream(resizedJpeg.Bytes); System.Diagnostics.Debug.WriteLine("Picture.OpenReadAsync=" + _stopwatch.Elapsed); var thumbnailSource = new BitmapImage(); //thumbnailSource.DecodePixelHeight = (int) ImageBorder.Height * 3; //thumbnailSource.DecodePixelWidth = (int) ImageBorder.Width * 3; thumbnailSource.CreateOptions = BitmapCreateOptions.BackgroundCreation; thumbnailSource.SetSource(stream); Image.Source = thumbnailSource; } }