Rank: Newbie
Groups: Guest
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
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 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
|
|
|
|
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.