0

I have a bug in my image editor with the blur tool.

When I select the rectangle to set the blur effect, and when I apply, result is a bit different see:

enter image description here enter image description here

To create the "Before" I do:

var blurredImage = ExtractImageToBlur(); // extract the selected area from image

BlurredImageRectangle.Fill = new ImageBrush(blurredImage);

var effect = new BlurEffect();
effect.KernelType = KernelType.Gaussian;
effect.RenderingBias = RenderingBias.Quality;
effect.Radius = m_blurValue;

BlurredImageRectangle.Effect = effect;

To create the "After", I do:

var blurredImage = ExtractImageToBlur(); // extract the selected area from image

Rectangle rectangleToRender = new Rectangle();

rectangleToRender.Fill = new ImageBrush(blurredImage);

var effect = new BlurEffect();
effect.KernelType = KernelType.Gaussian;
effect.RenderingBias = RenderingBias.Quality;
effect.Radius = m_blurValue;

rectangleToRender.Effect = effect;

Size size = new Size(croppedImg.PixelWidth, croppedImg.PixelHeight);
rectangleToRender.Measure(size);
rectangleToRender.Arrange(new Rect(size));

var render = new RenderTargetBitmap(croppedImg.PixelWidth, croppedImg.PixelHeight, 96, 96, PixelFormats.Pbgra32);
render.Render(rectangleToRender);

// Merge the source with the blurred section
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext context = drawingVisual.RenderOpen())
{
    int left = (int)(Canvas.GetLeft(BlurredImageRectangle) * WidthRatio);
    int top = (int)(Canvas.GetTop(BlurredImageRectangle) * HeightRatio);

    context.DrawImage(Source, new Rect(0, 0, Source.PixelWidth, Source.PixelHeight));
    context.DrawImage(render, new Rect(left, top, croppedImg.PixelWidth, croppedImg.PixelHeight));
}

var bitmap = new RenderTargetBitmap(Source.PixelWidth, Source.PixelHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(drawingVisual);

And when I play with the blur radius, its sometimes a lot more different from both images.

Why its not the same?

mlemay
  • 1,622
  • 2
  • 32
  • 53
  • Your question is unclear. You have two examples, which do not appear to illustrate the same problem. I.e. in one case, the "after" is more blurry than the "before", while in the other case it's _less_ blurry. It's also impossible to reproduce your problem without a good [mcve]. Please improve the question. – Peter Duniho Jan 19 '16 at 04:05

1 Answers1

0

Found the problem.

When I was drawing the rectangle on the screen, I applied the blur effect on the pixels on the screen.

When I hit save, the blur effect is applied on the pixel on the image on disk.

Huge difference.

mlemay
  • 1,622
  • 2
  • 32
  • 53