// This is the CreateImage() function body. private static Bitmap CreateImage( string sImageText ) { Bitmap bmpImage = new Bitmap( 1, 1 ); int iWidth = 0; int iHeight = 0; // Create the Font object for the image text drawing. Font MyFont = new Font( "Verdana", 24, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point ); // Create a graphics object to measure the text's width and height. Graphics MyGraphics = Graphics.FromImage( bmpImage ); // This is where the bitmap size is determined. iWidth = (int)MyGraphics.MeasureString( sImageText, MyFont ).Width; iHeight = (int)MyGraphics.MeasureString( sImageText, MyFont ).Height; // Create the bmpImage again with the correct size for the text and font. bmpImage = new Bitmap( bmpImage, new Size( iWidth, iHeight ) ); // Add the colors to the new bitmap. MyGraphics = Graphics.FromImage( bmpImage ); MyGraphics.Clear( Color.Navy ); MyGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; MyGraphics.DrawString( sImageText, MyFont, new SolidBrush( Color.Red ), 0, 0 ); MyGraphics.Flush(); return( bmpImage ); }
http://www.codeproject.com/Articles/6322/Another-Dynamic-ASP-NET-Text-Image
这个也是的:http://www.codeproject.com/Articles/2927/Creating-a-Watermarked-Photograph-with-GDI-for-NET
并且有源代码。