What I am trying to achieve is - I want to draw a text watermark on an image using GDI. This text watermark should be white and semi-transparent, shadow - grey semi-transparent. I tried this solution but obviously, when I draw a white semi-transparent text on top of a grey semi-transparent text, I see no white text at all, because grey pops up. Would be very helpful if anyone could guide me through this, as I have no experience with graphics at all. What I also tried, except of this:
drawing.DrawString(text, font, shadowBrush, x + shadowOffset.Width, y + shadowOffset.Height);
drawing.DrawString(text, font, textBrush, x, y);
Is, I tried to apply the outlining here. I thought that, maybe it is possible to apply the outlining at only one side so it would look like a shadow, but I failed on it either.
Here's the code I have so far:
var scalingRatio = GetWatermarkScalingRatio(image);
var scaledFontSize = (int)Math.Ceiling(scalingRatio * textProperties.Size);
var fontFamily = textProperties.Font ?? DefaultFont;
var alpha = (int)(255.0f * textProperties.Opacity / 100.0f);
var color = Color.FromArgb(alpha, Color.White);
using (var gr = Graphics.FromImage(image))
using (var font = new Font(fontFamily, scaledFontSize, DefaultFontStyle, GraphicsUnit.Pixel))
using (var semiTransparentBrush = new SolidBrush(color))
using (var shadowBrush = new SolidBrush(_shadowBrushColor))
{
var textSize = gr.MeasureString(textProperties.Message, font);
double wmWidth = textSize.Width;
double wmHeight = textSize.Height;
double angleRadian = (DefaultTextAngle % 360 / 180.0) * Math.PI;
var offset = GetTxtWatermarkOffset(textProperties.Position, image, wmWidth, wmHeight, angleRadian);
using var m = gr.Transform;
m.RotateAt(DefaultTextAngle, new PointF(offset.X, offset.Y), MatrixOrder.Append);
gr.Transform = m;
gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
gr.DrawString(textProperties.Message, font, shadowBrush, offset.X, offset.Y + DefaultShadowOffset);
gr.DrawString(textProperties.Message, font, semiTransparentBrush, offset.X, offset.Y);
gr.ResetTransform();
}