Generate transparent PNG with c#

by nolovelust 25. April 2010 21:44

private Bitmap CreateLogo(string subdomain)
{

    Bitmap objBmpImage = new Bitmap(1, 1);
    int intWidth = 0;
    int intHeight = 0;
    Font objFont = new Font("Arial", 13, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
    Graphics objGraphics = Graphics.FromImage(objBmpImage);
    intWidth = (int)objGraphics.MeasureString(subdomain, objFont).Width;
    intHeight = (int)objGraphics.MeasureString(subdomain, objFont).Height;
    objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
    objGraphics = Graphics.FromImage(objBmpImage);
    objGraphics.Clear(Color.Transparent);
    objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    objGraphics.DrawString(subdomain, objFont, new SolidBrush(Color.FromArgb(255, 255, 255)), 0, 0);
    objGraphics.Flush();
    return (objBmpImage);

}

Tags: , ,

ASP.NET | Open Source

Comments (1) -

Nathanael Jones
Nathanael Jones United States
5/24/2011 11:18:25 AM #

I noticed you frequently post articles about image resizing and watermarking, so you might be interested in the following:

nathanaeljones.com/163/20-image-resizing-pitfalls/ - All the common .net image mistakes

http://imageresizing.net/ - Lightweight, open-source library for image processing. Offers a querystring-based API for web projects as well.

Reply

Add comment

  Country flag

biuquote
Loading

Tag cloud

Month List