public BitmapSource GetBitmapSource(string albumId, int seqNo, bool allowBackgroundCreation = true) { Stream imageStream = this.GetImageStream(albumId, seqNo, false); ImageEffectsInfo imageEffectsInfo = this._sessionEffectsInfo.GetImageEffectsInfo(albumId, seqNo); if (!imageEffectsInfo.AppliedAny && imageEffectsInfo.ParsedExif != null && (imageEffectsInfo.ParsedExif.Orientation == ExifOrientation.TopRight || imageEffectsInfo.ParsedExif.Orientation == ExifOrientation.BottomLeft || imageEffectsInfo.ParsedExif.Orientation == ExifOrientation.BottomRight)) { return((BitmapSource)this.ReadOriginalImage(albumId, seqNo)); } BitmapImage bitmapImage1 = new BitmapImage(); if (allowBackgroundCreation) { bitmapImage1.CreateOptions = ((BitmapCreateOptions)16); } else { bitmapImage1.CreateOptions = ((BitmapCreateOptions)0); } BitmapImage bitmapImage2 = bitmapImage1; Size viewportSize = this.ViewportSize; // ISSUE: explicit reference operation int height = (int)((Size)@viewportSize).Height; bitmapImage2.DecodePixelHeight = height; ((BitmapSource)bitmapImage1).SetSource(imageStream); return((BitmapSource)bitmapImage1); }
public void SetCurrentPhoto(string albumId, int seqNo) { this._albumId = albumId; this._seqNo = seqNo; this._currentEffects = this._sessionEffectsInfo.GetImageEffectsInfo(albumId, seqNo); this.CallPropertyChanged(); }
public ImageEditorViewModel() { this._sessionId = Guid.NewGuid(); this.EnsureFolder(); this._sessionEffectsInfo = new SessionEffects(); this._viewportSize = ScaleFactor.GetScaleFactor() != 150 ? new Size((double)(480 * ScaleFactor.GetScaleFactor() / 100), (double)(800 * ScaleFactor.GetScaleFactor() / 100)) : new Size(720.0, 1280.0); this._currentEffects = new ImageEffectsInfo(); }
public Size GetCorrectImageSize(Picture p, string albumId, int seqNo, out bool rotated90) { ImageEffectsInfo imageEffectsInfo = this.GetImageEffectsInfo(albumId, seqNo); rotated90 = false; if (imageEffectsInfo.ParsedExif == null || imageEffectsInfo.ParsedExif.Orientation != ExifOrientation.TopRight && imageEffectsInfo.ParsedExif.Orientation != ExifOrientation.BottomLeft) { return(new Size((double)p.Width, (double)p.Height)); } rotated90 = true; return(new Size((double)p.Height, (double)p.Width)); }
public Stream GetImageStream(string albumId, int seqNo, bool preview = false) { ImageEffectsInfo imageEffectsInfo1 = this._sessionEffectsInfo.GetImageEffectsInfo(albumId, seqNo); if (!preview && imageEffectsInfo1.AppliedAny) { string pathForEffects = this.GetPathForEffects(albumId, seqNo); using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(pathForEffects, (FileMode)3, (FileAccess)1)) { MemoryStream exifStream = new MemoryStream(); if (imageEffectsInfo1.Exif != null) { exifStream = new MemoryStream(this.ResetOrientation(imageEffectsInfo1.ParsedExif.OrientationOffset, imageEffectsInfo1.Exif, imageEffectsInfo1.ParsedExif.LittleEndian)); } MemoryStream memoryStream = ImagePreprocessor.MergeExif((Stream)storageFileStream, exifStream); exifStream.Close(); return((Stream)memoryStream); } } } else { Stopwatch stopwatch = Stopwatch.StartNew(); Picture galleryImage = this.GetGalleryImage(albumId, seqNo); if (preview) { Stream thumbnail = galleryImage.GetThumbnail(); galleryImage.Dispose(); stopwatch.Stop(); return(thumbnail); } ImageEffectsInfo imageEffectsInfo2 = this.GetImageEffectsInfo(albumId, seqNo); Stream image = galleryImage.GetImage(); if (imageEffectsInfo2.Exif == null && !this.SuppressParseEXIF) { Stopwatch.StartNew(); MemoryStream exifStream; ImagePreprocessor.PatchAwayExif(image, out exifStream); image.Position = 0L; imageEffectsInfo2.Exif = new byte[exifStream.Length]; exifStream.Read(imageEffectsInfo2.Exif, 0, (int)exifStream.Length); JpegInfo info = new ExifReader(image).info; imageEffectsInfo2.ParsedExif = info; image.Position = 0L; } stopwatch.Stop(); galleryImage.Dispose(); return(image); } }
private void UpdateFiltersState(string forceFilterName = "", Action callback = null) { ImageEffectsInfo imageEffectsInfo = this.ImageEditor.GetImageEffectsInfo(this._albumId, this.CurrentPhotoSeqNo); string str = string.IsNullOrEmpty(forceFilterName) ? imageEffectsInfo.Filter : forceFilterName; foreach (FilterViewModel filter in this.Filters) { bool flag = str == filter.FilterName; filter.IsSelectedVisibility = flag ? Visibility.Visible : Visibility.Collapsed; if (flag) { this.ScrollToIndex(this.Filters.IndexOf(filter), callback); } } }
private void TextEffectTap(object sender, System.Windows.Input.GestureEventArgs e) { this._de = new DialogService(); EditPhotoTextUC uc = new EditPhotoTextUC(); ImageEffectsInfo imageEffectsInfo = this._imageEditorVM.GetImageEffectsInfo(this._albumId, this.CurrentPhotoSeqNo); uc.TextBoxText.Text = (imageEffectsInfo.Text ?? ""); uc.ButtonSave.Click += (delegate(object s, RoutedEventArgs ev) { string text = uc.TextBoxText.Text; Deployment.Current.Dispatcher.BeginInvoke(delegate { this.ImageEditor.SetResetText(text, new Action <BitmapSource>((b) => { this.HandleEffectApplied(b); })); }); this._de.Hide(); }); this._de.Child = uc; this._de.HideOnNavigation = false; this._de.Show(this.gridDecorator); }
public ImageEffectsInfo GetImageEffectsInfo(string albumId, int seqNo) { ImageEffectsInfo imageEffectsInfo = this._effectsList.FirstOrDefault <ImageEffectsInfo>((Func <ImageEffectsInfo, bool>)(e => { if (e.AlbumId == albumId) { return(e.SeqNo == seqNo); } return(false); })); if (imageEffectsInfo == null) { imageEffectsInfo = new ImageEffectsInfo() { AlbumId = albumId, SeqNo = seqNo }; this._effectsList.Add(imageEffectsInfo); } return(imageEffectsInfo); }
public WriteableBitmap RotateIfNeeded(string aId, int sNo, WriteableBitmap wb) { ImageEffectsInfo imageEffectsInfo = this._sessionEffectsInfo.GetImageEffectsInfo(aId, sNo); if (imageEffectsInfo.ParsedExif != null) { switch (imageEffectsInfo.ParsedExif.Orientation) { case ExifOrientation.BottomRight: wb = wb.Rotate(180); break; case ExifOrientation.TopRight: wb = wb.Rotate(90); break; case ExifOrientation.BottomLeft: wb = wb.Rotate(270); break; } } return(wb); }
private void ToggleCropMode() { if (this._isInSetResetCrop) { return; } if (this._inCropMode) { this._inCropMode = false; this._inSelectOwnPhotoArea = false; ((UIElement)this.gridChooseThumbnail).Visibility = Visibility.Collapsed; ((UIElement)this.gridCropLines).Visibility = Visibility.Collapsed; ((UIElement)this.gridCrop).Visibility = Visibility.Collapsed; this.imageViewer.Mode = ImageViewerMode.Normal; ((UIElement)this.stackPanelEffects).Visibility = Visibility.Visible; ((UIElement)this.stackPanelCrop).Visibility = Visibility.Collapsed; this.UpdateImageAndEllipseSelectOpacity(1); } else { this._inCropMode = true; Picture galleryImage = this._imageEditorVM.GetGalleryImage(this._albumId, this.CurrentPhotoSeqNo); bool rotated90 = false; Size correctImageSize = this._imageEditorVM.GetCorrectImageSize(galleryImage, this._albumId, this.CurrentPhotoSeqNo, out rotated90); BitmapImage bitmapImage = new BitmapImage(); Point point = new Point(); Size viewportSize = this._imageEditorVM.ViewportSize; // ISSUE: explicit reference operation double num1 = ((Size)@viewportSize).Width * 2.0; viewportSize = this._imageEditorVM.ViewportSize; // ISSUE: explicit reference operation double num2 = ((Size)@viewportSize).Height * 2.0; Size size = new Size(num1, num2); Rect fit1 = RectangleUtils.ResizeToFit(new Rect(point, size), correctImageSize); // ISSUE: explicit reference operation if (((Rect)@fit1).Height < (double)galleryImage.Height) { // ISSUE: explicit reference operation // ISSUE: explicit reference operation bitmapImage.DecodePixelHeight = (rotated90 ? (int)((Rect)@fit1).Height : (int)((Rect)@fit1).Width); } ((BitmapSource)bitmapImage).SetSource(galleryImage.GetImage()); this.imageViewer.CurrentImage.Source = ((ImageSource)this._imageEditorVM.RotateIfNeeded(this._albumId, this.CurrentPhotoSeqNo, new WriteableBitmap((BitmapSource)bitmapImage))); this.imageViewer.RectangleFill = ScaleFactor.GetScaleFactor() != 150 ? new Rect(12.0, 136.0, 456.0, 456.0) : new Rect(12.0, 163.0, 456.0, 456.0); this.imageViewer.Mode = ImageViewerMode.RectangleFill; ImageEffectsInfo imageEffectsInfo = this._imageEditorVM.GetImageEffectsInfo(this._albumId, this.CurrentPhotoSeqNo); if (imageEffectsInfo.CropRect != null) { Rect rect1 = new Rect(); // ISSUE: explicit reference operation rect1.X = ((double)imageEffectsInfo.CropRect.X); // ISSUE: explicit reference operation rect1.Y = ((double)imageEffectsInfo.CropRect.Y); // ISSUE: explicit reference operation rect1.Width = ((double)imageEffectsInfo.CropRect.Width); // ISSUE: explicit reference operation rect1.Height = ((double)imageEffectsInfo.CropRect.Height); Rect rect2 = rect1; Rect fit2 = RectangleUtils.ResizeToFit(new Rect(new Point(), new Size(((FrameworkElement)this.imageViewer).Width, ((FrameworkElement)this.imageViewer).Height)), correctImageSize); ((UIElement)this.imageViewer.CurrentImage).RenderTransform = ((Transform)RectangleUtils.TransformRect(((GeneralTransform)RectangleUtils.TransformRect(new Rect(new Point(), correctImageSize), fit2, false)).TransformBounds(rect2), this.imageViewer.RectangleFill, false)); } else { this.imageViewer.AnimateToRectangleFill(); } galleryImage.Dispose(); this.ShowHideGridFilters(false); ((UIElement)this.gridCropLines).Visibility = Visibility.Visible; ((UIElement)this.gridCrop).Visibility = Visibility.Visible; ((UIElement)this.stackPanelEffects).Visibility = Visibility.Collapsed; ((UIElement)this.stackPanelCrop).Visibility = Visibility.Visible; this.UpdateImageAndEllipseSelectOpacity(0); } }
public void Show(int totalCount, string albumId, int ind, Func <int, Image> getImageFunc, Action <int, bool> showHideOriginalImageCallback, PhotoPickerPhotos pickerPage) { if (this.IsShown) { return; } ((UIElement)this).Visibility = Visibility.Visible; this._indToShow = ind; if (this._pppVM != null) { this._pppVM.PropertyChanged -= new PropertyChangedEventHandler(this.PickerVM_PropertyChanged); } this._pppVM = pickerPage.VM; this._pppVM.PropertyChanged += new PropertyChangedEventHandler(this.PickerVM_PropertyChanged); this._pickerPage = pickerPage; this._totalCount = totalCount; this._savedPageAppBar = this.Page.ApplicationBar; this._albumId = albumId; this._imageEditorVM = this._pickerPage.VM.ImageEditor; ((UIElement)this.elliplseSelect).Opacity = (0.0); ((UIElement)this.imageSelect).Opacity = (0.0); this.OnPropertyChanged("ImageEditor"); this.InitializeImageSizes(); PhoneApplicationPage page = this.Page; // ISSUE: variable of the null type page.ApplicationBar = (null); EventHandler <CancelEventArgs> eventHandler = new EventHandler <CancelEventArgs>(this.Page_BackKeyPress); page.BackKeyPress += (eventHandler); this.UpdateConfirmButtonState(); this.imageViewer.Initialize(totalCount, (Func <int, ImageInfo>)(i => { double num1 = 0.0; double num2 = 0.0; if (this._imageSizes.Count > i) { Size imageSize1 = this._imageSizes[i]; // ISSUE: explicit reference operation num1 = ((Size)@imageSize1).Width; Size imageSize2 = this._imageSizes[i]; // ISSUE: explicit reference operation num2 = ((Size)@imageSize2).Height; } ImageEffectsInfo imageEffectsInfo = this._imageEditorVM.GetImageEffectsInfo(this._albumId, this._totalCount - i - 1); if (imageEffectsInfo != null && imageEffectsInfo.ParsedExif != null && (imageEffectsInfo.ParsedExif.Width != 0 && imageEffectsInfo.ParsedExif.Height != 0)) { num1 = (double)imageEffectsInfo.ParsedExif.Width; num2 = (double)imageEffectsInfo.ParsedExif.Height; if (imageEffectsInfo.ParsedExif.Orientation == ExifOrientation.TopRight || imageEffectsInfo.ParsedExif.Orientation == ExifOrientation.BottomLeft) { double num3 = num1; num1 = num2; num2 = num3; } } if (imageEffectsInfo != null && imageEffectsInfo.CropRect != null && !this._inCropMode) { num1 = (double)imageEffectsInfo.CropRect.Width; num2 = (double)imageEffectsInfo.CropRect.Height; } return(new ImageInfo() { GetSourceFunc = (Func <bool, BitmapSource>)(allowBackgroundCreation => this._imageEditorVM.GetBitmapSource(this._albumId, this._totalCount - i - 1, allowBackgroundCreation)), Width = num1, Height = num2 }); }), getImageFunc, showHideOriginalImageCallback, (FrameworkElement)null, (Action <int>)null); this.IsShown = true; this.ShowViewer(); }