This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Draw Text on Transparent Image

I'm trying to draw text onto a transparent png but not having success.

Its always black text on a white background-- how to make it transparent?

using (var bitmap = new Bitmap(Convert.ToInt32(Width.Value), Convert.ToInt32(Height.Value), PixelFormat.Format32bppArgb, new RgbColor(255, 255, 255, 255)))
{
    using (var graphics = bitmap.GetAdvancedGraphics())
    {
        using (var fontRegistry = new CustomFontRegistry())
        {
            var brush = new SolidBrush(color);
            var customFont = CustomFontCollection.TryGetAurigmaFont(Font);
            float dpi = 300;

            BoundedText text = null;

            Aurigma.GraphicsMill.AdvancedDrawing.Font font = null;

            if (!string.IsNullOrEmpty(customFont))
            {
                var psName = fontRegistry.Add(customFont);
                font = fontRegistry.CreateFont(psName, (float)FontSize, 72, 72);
                dpi = font.DpiX;
            }
            else
            {
                font = graphics.CreateFont(Font, (float)FontSize);
            }

            
            text = new BoundedText(Text, font, new System.Drawing.RectangleF(0, 0, (float)Width.Value, (float)Height.Value));
            text.Pen = new Pen(color);

            graphics.DrawText(text);
            _RenderedFontGraphicsFile = ctx.GetPathToNewTempFile("hi.png");
            bitmap.Save(_RenderedFontGraphicsFile);
        }
    }
}
Hi Austen,

Just create a bitmap with the transparent background:

using (var bitmap = new Bitmap(Convert.ToInt32(Width.Value), Convert.ToInt32(Height.Value), PixelFormat.Format32bppArgb, new RgbColor(255, 255, 255, 0)))


The constructor of RgbColor accepts the value of Red, Green, Value and Alpha channels. The value 0 of Alpha defines totally transparent color.