private async Task SetupNewTool(ImageEditorTool newValue) { // var stream = await this.Source.OpenReadAsync(); //var properties = await this.Source.Properties.GetImagePropertiesAsync(); if (this.Source != null && newValue != null) { if (newValue is ImageEditorEffectTool) { this.RevertPreviewBitmap(); } await newValue.Init(this.previewBitmap, this as IToolValueProvider); } if (newValue is IRotateTool) { if (newValue.workingBitmap != null) { this.previewBitmap = newValue.workingBitmap; this.previewBitmap.Invalidate(); this.ModifiedImage = this.previewBitmap; } newValue.IsSelected = false; } }
/// <summary> /// A virtual callback that is called when the <see cref="CurrentTool"/> property changes. /// </summary> /// <param name="newValue"></param> /// <param name="oldValue"></param> protected async virtual void OnCurrentToolChanged(ImageEditorTool newValue, ImageEditorTool oldValue) { if (oldValue != null) { oldValue.CleanUp(); bool shouldDeselect = !(oldValue is ImageEditorEffectTool && newValue != null && !(newValue is ImageEditorEffectTool)); if (shouldDeselect) { oldValue.IsSelected = false; } } if (newValue != null) { if (newValue is ImageEditorEffectTool) { var group = this.SelectedGroup as ImageEditorToolGroup; var selectedTools = group.Tools.Where((ImageEditorTool tool) => { return(tool != newValue && tool.IsSelected); }); foreach (var tool in selectedTools) { tool.IsSelected = false; } } await this.SetupNewTool(newValue); } this.ResetImageManipulations(); this.SelectLayer(newValue); }
private void OnToolPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "IsSelected") { ImageEditorTool tool = (ImageEditorTool)sender; if (tool.IsSelected) { this.CurrentTool = tool; } else if (this.CurrentTool == sender) { this.CurrentTool = null; } } else if (e.PropertyName == "Value") { RangeTool tool = sender as RangeTool; if (tool != null) { this.StatusMessage = tool.Value.ToString(); } } //if (e.PropertyName == "ModifiedImage" && this.CurrentTool != null) //{ // this.ModifiedImage = this.CurrentTool.ModifiedImage; //} }
private void SelectLayer(ImageEditorTool tool) { this.RemoveLayer(this.toolLayer, this.imageHost); this.toolLayer = this.LayerSelector != null?this.LayerSelector.SelectLayer(tool) : null; this.AddLayer(this.toolLayer, this.imageHost); this.InvalidateArrange(); }
private async Task ApplyTool(ImageEditorTool tool, IRandomAccessStream stream) { if (!tool.HandleApply()) { this.previewBitmap = await tool.Apply(this.previewBitmapStream, this.previewBitmap); this.previewBitmap.Invalidate(); var newSize = new Size(this.previewBitmap.PixelWidth, this.previewBitmap.PixelHeight); if (this.RotatedImageSize.Width != 0 && this.RotatedImageSize.Height != 0) { if (newSize.Width != this.RotatedImageSize.Width || newSize.Height != this.RotatedImageSize.Height) { this.OriginalImageSize = newSize; } } else { this.OriginalImageSize = newSize; } } this.ModifiedImage = this.previewBitmap; var destStream = new InMemoryRandomAccessStream(); var pixelStream = this.previewBitmap.PixelBuffer.AsStream(); byte[] pixels = new byte[pixelStream.Length]; BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destStream); pixelStream.ReadAsync(pixels, 0, pixels.Length).Wait(); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)this.previewBitmap.PixelWidth, (uint)this.previewBitmap.PixelHeight, 96.0, 96.0, pixels); await encoder.FlushAsync(); this.previewBitmapStream = destStream; }