This project has moved and is read-only. For the latest updates, please go here.

Caption background color ignored

Sep 11, 2015 at 7:59 PM
Edited Sep 11, 2015 at 8:01 PM
I am trying to place colored text on a black caption area. However, it seems no matter what I set the background color it doesn't change. The caption area is always remains white. Any ideas what is going on?
Using Any-Cpu version in VS2013
                'Add Timestamp Caption

                    Dim CaptionbgColor = New MagickColor("#000000") 'Color for the caption background color doesn't seem to take
                    Dim CaptionfontFamily = "Arial-Italic"

                    Using timestampImage = New MagickImage(CaptionbgColor, 352, 14)
                        timestampImage.FillColor = New MagickColor("#9900FF") '__This works__ and changes the font color
                        timestampImage.Font = CaptionfontFamily
                        timestampImage.FontPointsize = 12
                        timestampImage.Read("caption:As of " + Now.ToString)

                        image.Composite(timestampImage, Gravity.North, CompositeOperator.Over)
                        'Save the result
                        image.Write(myFilesTempOutputDirectory + "imagePostOverlayCaption.jpg")
                    End Using
Sep 11, 2015 at 9:14 PM
Your issue is that you are expecting that the background color is set to the color that you specify when you read the image but that doesn't happen at the moment. I understand that this would be logical so this will be changed in the next release of Magick.NET. This will only be changed in the MagickImage constructor that accepts a MagickColor. I will not change that in the Read method that has a color argument because that could possibly break someone their code.

For now you will need to specify the background color after you created the canvas:
MagickColor backgroundColor = new MagickColor("Purple");

using (MagickImage timestampImage = new MagickImage(backgroundColor, 352, 14))
  timestampImage.BackgroundColor = backgroundColor;
  timestampImage.FillColor = new MagickColor("#9900FF");
  timestampImage.Font = "Arial-Italic";
  timestampImage.FontPointsize = 12;
  timestampImage.Read("caption:As of " + DateTime.Now.ToString());
Sep 14, 2015 at 2:03 PM
Thanks, that worked.