private void ApplyEffects(WriteableBitmap croppedResizedWB, Action <WriteableBitmap> callback) { Stopwatch.StartNew(); if (croppedResizedWB == null) { if (this._currentEffects.CropRect != null || this._currentEffects.RotateAngle != 0.0) { croppedResizedWB = this.ReadCroppedImage(); } else { croppedResizedWB = this.ReadOriginalImage("", -1); } } croppedResizedWB = this.ApplyContrastIfNeeded(croppedResizedWB); this.ApplyFilterIfNeeded(croppedResizedWB, delegate(WriteableBitmap filteredWB) { Execute.ExecuteOnUIThread(delegate { filteredWB = this.ApplyTextIfNeeded(filteredWB); ImageEditorViewModel.SaveWB(filteredWB, this.GetPathForEffects(this._albumId, this._seqNo)); callback.Invoke(filteredWB); croppedResizedWB = null; filteredWB = null; GC.Collect(); }); }); }
private void SetCrop(object sender, System.Windows.Input.GestureEventArgs e) { if (this._inSelectOwnPhotoArea) { ParametersRepository.SetParameterForId("UserPicSquare", (object)this.imageViewer.RectangleFillRelative); this._inSelectOwnPhotoArea = false; ((UIElement)this.gridChooseThumbnail).Visibility = Visibility.Collapsed; this.EnsureSelectCurrentAndConfirm(); } else { if (this._isInSetResetCrop) { return; } this._isInSetResetCrop = true; ParametersRepository.SetParameterForId("UserPicSquare", (object)new Rect(0.0, 0.0, 1.0, 1.0)); Rect rectToCrop = this.imageViewer.RectangleFillInCurrentImageCoordinates; ((DependencyObject)Deployment.Current).Dispatcher.BeginInvoke((Action)(() => { ImageEditorViewModel imageEditorVm = this._imageEditorVM; double rotate = 0.0; CropRegion rect = new CropRegion(); // ISSUE: explicit reference operation rect.X = (int)((Rect)@rectToCrop).X; // ISSUE: explicit reference operation rect.Y = (int)((Rect)@rectToCrop).Y; // ISSUE: explicit reference operation rect.Width = (int)((Rect)@rectToCrop).Width; // ISSUE: explicit reference operation rect.Height = (int)((Rect)@rectToCrop).Height; WriteableBitmap source = this.imageViewer.CurrentImage.Source as WriteableBitmap; Action <BitmapSource> callback = (Action <BitmapSource>)(result => { this._isInSetResetCrop = false; this.HandleEffectApplied(result); this.ToggleCropMode(); ((UIElement)this.imageViewer.CurrentImage).RenderTransform = ((Transform)RectangleUtils.TransformRect(this.imageViewer.CurrentImageFitRectOriginal, this.imageViewer.RectangleFill, false)); this.imageViewer.AnimateImage(1.0, 1.0, 0.0, 0.0, (Action)null); }); imageEditorVm.SetCrop(rotate, rect, source, callback); })); } }
public void SetCrop(double rotate, CropRegion rect, WriteableBitmap imSource, Action <BitmapSource> callback) { if (this.ApplyingEffects) { return; } this.ApplyingEffects = true; Action <WriteableBitmap> _9__1 = null; Deployment.Current.Dispatcher.BeginInvoke(delegate { WriteableBitmap imSource2 = imSource; Picture galleryImage = this.GetGalleryImage(this._albumId, this._seqNo); bool flag = false; double num = this.GetCorrectImageSize(galleryImage, this._albumId, this._seqNo, out flag).Width / (double)imSource2.PixelWidth; galleryImage.Dispose(); WriteableBitmap writeableBitmap = imSource2.Crop((int)((double)rect.X / num), (int)((double)rect.Y / num), (int)((double)rect.Width / num), (int)((double)rect.Height / num)); Rect rect2 = RectangleUtils.ResizeToFit(new Rect(default(Point), this.ViewportSize), new Size((double)writeableBitmap.PixelWidth, (double)writeableBitmap.PixelHeight)); WriteableBitmap writeableBitmap2 = writeableBitmap.Resize((int)rect2.Width, (int)rect2.Height, Interpolation.Bilinear); ImageEditorViewModel.SaveWB(writeableBitmap2, this.GetPathForCrop()); this._currentEffects.CropRect = rect; this._currentEffects.RotateAngle = rotate; ImageEditorViewModel arg_167_0 = this; WriteableBitmap arg_167_1 = writeableBitmap2; Action <WriteableBitmap> arg_167_2; if ((arg_167_2 = _9__1) == null) { arg_167_2 = (_9__1 = delegate(WriteableBitmap bitmap) { callback.Invoke(bitmap); this.ApplyingEffects = false; }); } arg_167_0.ApplyEffects(arg_167_1, arg_167_2); this.CallPropertyChanged(); }); }
private WriteableBitmap ApplyTextIfNeeded(WriteableBitmap wb) { if (string.IsNullOrWhiteSpace(this._currentEffects.Text)) { return(wb); } WriteableBitmap writeableBitmap = new WriteableBitmap((BitmapSource)wb); double fontSize; double yTranlsation; this.GetFontSizeAndYTranslation(((BitmapSource)wb).PixelWidth, ((BitmapSource)wb).PixelHeight, out fontSize, out yTranlsation); TextBlock textBlock1 = ImageEditorViewModel.CreateTextBlock(this._currentEffects.Text, fontSize); textBlock1.Foreground = ((Brush) new SolidColorBrush(Colors.Black)); ((UIElement)textBlock1).Opacity = 0.6; ((FrameworkElement)textBlock1).Width = ((double)((BitmapSource)wb).PixelWidth - yTranlsation * 2.0); TextBlock textBlock2 = ImageEditorViewModel.CreateTextBlock(this._currentEffects.Text, fontSize); ((FrameworkElement)textBlock2).Width = ((double)((BitmapSource)wb).PixelWidth - yTranlsation * 2.0); Size size; // ISSUE: explicit reference operation size = new Size((double)((BitmapSource)wb).PixelWidth, (double)((BitmapSource)wb).PixelHeight); Rectangle rectangle1 = new Rectangle(); Rectangle rectangle2 = rectangle1; GradientStopCollection gradientStopCollection = new GradientStopCollection(); GradientStop gradientStop1 = new GradientStop(); Color color1 = new Color(); // ISSUE: explicit reference operation color1.A = ((byte)0); Color color2 = color1; gradientStop1.Color = color2; ((PresentationFrameworkCollection <GradientStop>)gradientStopCollection).Add(gradientStop1); GradientStop gradientStop2 = new GradientStop(); color1 = new Color(); // ISSUE: explicit reference operation color1.A = byte.MaxValue; Color color3 = color1; gradientStop2.Color = color3; double num1 = 1.0; gradientStop2.Offset = num1; ((PresentationFrameworkCollection <GradientStop>)gradientStopCollection).Add(gradientStop2); double num2 = 90.0; LinearGradientBrush linearGradientBrush = new LinearGradientBrush(gradientStopCollection, num2); ((Shape)rectangle2).Fill = ((Brush)linearGradientBrush); ((UIElement)rectangle1).Opacity = 0.4; ((FrameworkElement)rectangle1).Height = (((FrameworkElement)textBlock2).ActualHeight + yTranlsation + yTranlsation); ((FrameworkElement)rectangle1).Width = ((double)((BitmapSource)wb).PixelWidth); Rectangle rectangle3 = rectangle1; TranslateTransform translateTransform1 = new TranslateTransform(); // ISSUE: explicit reference operation double num3 = ((Size)@size).Height - ((FrameworkElement)rectangle1).Height; translateTransform1.Y = num3; writeableBitmap.Render((UIElement)rectangle3, (Transform)translateTransform1); TextBlock textBlock3 = textBlock1; TranslateTransform translateTransform2 = new TranslateTransform(); double num4 = yTranlsation + 1.0; translateTransform2.X = num4; // ISSUE: explicit reference operation double num5 = ((Size)@size).Height - ((FrameworkElement)textBlock2).ActualHeight - yTranlsation; translateTransform2.Y = num5; writeableBitmap.Render((UIElement)textBlock3, (Transform)translateTransform2); TextBlock textBlock4 = textBlock2; TranslateTransform translateTransform3 = new TranslateTransform(); double num6 = yTranlsation; translateTransform3.X = num6; // ISSUE: explicit reference operation double num7 = ((Size)@size).Height - ((FrameworkElement)textBlock2).ActualHeight - yTranlsation - 1.0; translateTransform3.Y = num7; writeableBitmap.Render((UIElement)textBlock4, (Transform)translateTransform3); writeableBitmap.Invalidate(); return(writeableBitmap); }
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(); }