This project has moved. For the latest updates, please go here.

It seems that blur is doing something strange.

Feb 3, 2015 at 9:12 AM
Edited Feb 3, 2015 at 9:17 AM
I'm trying to apply round mask to pictures. The code for creating mask is below:
    private static MagickImage CreateMask(int diameter)
    {
        var mask = new MagickImage(MagickColor.Transparent, diameter, diameter);
        mask.FillColor = new MagickColor(Color.Black);
        mask.Draw(new DrawableCircle(diameter / 2.0, diameter / 2.0, diameter / 2.0, 0));
        //mask.Blur(0, 1);
        mask.Negate();
        mask.Alpha(AlphaOption.Deactivate);
        return mask;
    }
This code creates perfect mask. But it is, ehrm, edgy. I'd like to blur it a little, so I uncomment string with Blur in source code and it returns to me white square mask. It's not what I'm expecting.

Where and what did I wrong? Thank you.
Coordinator
Feb 3, 2015 at 11:11 AM
Edited Feb 3, 2015 at 12:58 PM
This looks like a bug in ImageMagick, I will investigate this for you. You can however make this method a bit simpler. If you start with a black background and you draw a white circle you won't need the alpha channel. It seems that it is causing the issue.
private static MagickImage CreateMask(int diameter)
{
  var mask = new MagickImage(Color.Black, diameter, diameter);
  mask.FillColor = new MagickColor(Color.White);
  mask.Draw(new DrawableCircle(diameter / 2.0, diameter / 2.0, diameter / 2.0, 0));
  mask.Blur(0, 1);
  return mask;
}
EDIT:

This is not a bug but caused by mask.Alpha(AlphaOption.Deactivate). When you create a transparent image this creates an image with pixels that have the following color: R=0, G=0, B=0, A=0. When you negate this the alpha channel won't be negated but it will turn the transparent pixels into the following color: R=65535, G=65535, B=65535, A=0. When you call mask.Alpha(AlphaOption.Deactivate) this will remove the alpha channel and change all the transparent pixels into the following color: R=65535, G=65535, B=65535. And because your non transparent pixels are white this will make the whole image white.