I'm using the following code to put text on a gradient background:
Code: Select all
using ImageMagick;
namespace TextToPicture
{
class Slideshow
{
static void Main(string[] args)
{
using (var image = new MagickImage(MagickColors.White, 320, 240))
{
image.Density = new Density(300);
image.Format = MagickFormat.Png;
using (var gradient = new MagickImage(@"D:\gradient.png", 320, 240))
image.Composite(gradient, 0, 0, CompositeOperator.Over);
using (var completeMask = new MagickImage(MagickColors.Transparent, 310, 30))
{
using (var filledMask = new MagickImage(MagickColors.White, 310, 30))
completeMask.Composite(filledMask, 0, 0, CompositeOperator.Over);
using (var mText = new MagickImage(MagickColors.Transparent, 310, 30))
{
var textSettings = new MagickReadSettings
{
BackgroundColor = MagickColors.Transparent,
Width = 310,
Height = 30,
TextGravity = Gravity.North
};
mText.Read($"caption:Hello World!", textSettings);
using (var completeTextBox = new MagickImage(MagickColors.Transparent, 310, 30))
{
completeTextBox.Composite(mText, 0, 0, CompositeOperator.Over);
completeTextBox.Composite(completeMask, 0, 0);
image.Composite(completeTextBox, 5, 60, CompositeOperator.Dissolve, "100");
}
}
}
image.Write(@"D:\test.png");
}
}
}
}
The reason I compose an image over transparent text instead of just applying color to the text is so I can make it fade out to nothing depending on settings, this image composite is normally a gradient. (see my previous post). This is just a simplified example to show my issue.
The issue I'm facing is: The anti-aliasing is very rough because it seems to be using black instead of white as 'color to "anti-aliase"'
Any idea what could cause this?
I'm using Magick.NET v7.6.0 targeting .NET Framework 4.6.1 .
The image gradient I've used (D:\gradient.png) is provided below.
Thanks.