private void OnHsvWheelSizeChanged(object sender, SizeChangedEventArgs e) { if (_imageElement == null) { return; } SizeChanged -= OnHsvWheelSizeChanged; var width = Convert.ToInt32(e.NewSize.Width); var height = Convert.ToInt32(e.NewSize.Height); var diameter = width < height ? width : height; diameter = 3000; var radius = diameter / 2; var source = new WriteableBitmap(diameter, diameter); var pixels = source.PixelBuffer.GetPixels(); var array = new double[diameter, diameter]; for (var i = 0; i < diameter * diameter; i++) { var x = i % diameter; var y = i / diameter; var distance = Math.Sqrt(Math.Pow(radius - x, 2) + Math.Pow(radius - y, 2)); var saturation = distance / radius; array[x, y] = saturation; if (saturation >= 1) { pixels.Bytes[i * 4] = 0; pixels.Bytes[i * 4 + 1] = 0; pixels.Bytes[i * 4 + 2] = 0; pixels.Bytes[i * 4 + 3] = 0; } else { var distanceOfX = x - radius; var distanceOfY = y - radius; var theta = Math.Atan2(distanceOfY, distanceOfX); if (theta < 0) { theta += 2 * Math.PI; } var hue = theta / (Math.PI * 2) * 360.0; var color = ColorHelper.FromHsv(hue, saturation, 1); pixels.Bytes[i * 4] = color.B; pixels.Bytes[i * 4 + 1] = color.G; pixels.Bytes[i * 4 + 2] = color.R; pixels.Bytes[i * 4 + 3] = 255; } } pixels.UpdateFromBytes(); source.Invalidate(); source = source.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5); //ImgBlur.Source = blurredBitmap; _imageElement.Source = source; }
private void ChangeBitmap() { if (this.selectedMode == MODE_CLONE) { if (this.samplingPointValid) { int width = Math.Min(this.brushBitmap.PixelWidth, this.editedBitmap.PixelWidth); int height = Math.Min(this.brushBitmap.PixelHeight, this.editedBitmap.PixelHeight); Rect src_rect = new Rect(); src_rect.X = Math.Min(Math.Max(0, this.samplingPoint.X - width / 2), this.editedBitmap.PixelWidth - width); src_rect.Y = Math.Min(Math.Max(0, this.samplingPoint.Y - height / 2), this.editedBitmap.PixelHeight - height); src_rect.Width = width; src_rect.Height = height; Rect dst_rect = new Rect(); dst_rect.X = Math.Min(Math.Max(0, this.clonePoint.X - width / 2), this.editedBitmap.PixelWidth - width); dst_rect.Y = Math.Min(Math.Max(0, this.clonePoint.Y - height / 2), this.editedBitmap.PixelHeight - height); dst_rect.Width = width; dst_rect.Height = height; Rect brh_rect = new Rect(0, 0, width, height); WriteableBitmap brush_bitmap = new WriteableBitmap(width, height); brush_bitmap.Blit(brh_rect, this.editedBitmap, src_rect, WriteableBitmapExtensions.BlendMode.None); brush_bitmap.Blit(brh_rect, this.brushBitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Mask); this.editedBitmap.Blit(dst_rect, brush_bitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Alpha); this.EditorImage.Source = this.editedBitmap; } } else if (this.selectedMode == MODE_BLUR) { int width = Math.Min(this.brushBitmap.PixelWidth, this.editedBitmap.PixelWidth); int height = Math.Min(this.brushBitmap.PixelHeight, this.editedBitmap.PixelHeight); Rect src_rect = new Rect(); src_rect.X = Math.Min(Math.Max(0, this.blurPoint.X - width / 2), this.editedBitmap.PixelWidth - width); src_rect.Y = Math.Min(Math.Max(0, this.blurPoint.Y - height / 2), this.editedBitmap.PixelHeight - height); src_rect.Width = width; src_rect.Height = height; Rect blr_rect = new Rect(0, 0, width, height); WriteableBitmap blur_bitmap = new WriteableBitmap(width, height); blur_bitmap.Blit(blr_rect, this.editedBitmap, src_rect, WriteableBitmapExtensions.BlendMode.None); blur_bitmap = blur_bitmap.Convolute(GAUSSIAN_KERNEL); this.editedBitmap.Blit(src_rect, blur_bitmap, blr_rect, WriteableBitmapExtensions.BlendMode.None); this.EditorImage.Source = this.editedBitmap; } }
private WriteableBitmap ApplyContrastIfNeeded(WriteableBitmap wb) { if (this._currentEffects.Contrast) { return(wb.Convolute(WriteableBitmapExtensions.KernelSharpen3x3)); } return(wb); }
/// <summary> /// Creates a new filtered WriteableBitmap. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="kernel">The kernel used for convolution.</param> /// <returns>A new WriteableBitmap that is a filtered version of the input.</returns> public static WriteableBitmap Convolute(this WriteableBitmap bmp, int[,] kernel) { var kernelFactorSum = 0; foreach (var b in kernel) { kernelFactorSum += b; } return(bmp.Convolute(kernel, kernelFactorSum, 0)); }
public static WriteableBitmap Convolute(WriteableBitmap bmp, int[,] kernel) { int kernelFactorSum = 0; foreach (var b in kernel) { kernelFactorSum += Math.Abs(b); } return(bmp.Convolute(kernel, kernelFactorSum, 0)); }
public static void GaussianBlur(this WriteableBitmap bmp) { bmp.Convolute(_gaussianBlurKernel, 5, 5); }
public static void GaussianBlurTiny(this WriteableBitmap bmp) { bmp.Convolute(_tinyGaussianBlurKernel, 3, 3); }
public static void GaussianBlur(this WriteableBitmap bmp, int kernelWidth, int kernelHeight) { bmp.Convolute(_gaussianBlurKernel, kernelWidth, kernelHeight); }