Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
austen.bernstein  
#1 Posted : Wednesday, July 1, 2015 8:32:43 AM(UTC)
austen.bernstein

Rank: Newbie

Groups: Member
Joined: 7/1/2015(UTC)
Posts: 3

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?

Code:
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);
        }
    }
}

Edited by moderator Wednesday, July 1, 2015 8:37:43 AM(UTC)  | Reason: Not specified

Fedor  
#2 Posted : Wednesday, July 1, 2015 9:02:27 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Hi Austen,

Just create a bitmap with the transparent background:

Code:
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.

Edited by user Wednesday, July 1, 2015 9:05:03 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.