CreateTextImage

Useful for creating text header images etc.

Most simple use:

CreateTextImageToFile(String text, Font font, Color foreColor, Color backColor, int maxWidth, String outputFileName)

e.g.

Font arial = new Font("Arial", "20", FontStyle.Regular, GraphicsUnit.Pixel);
ImageAide.CreateTextImageToFile("Hello", arial, Color.Black, Color.White, 200, @"c:\websites\test\images\header\hello.gif");


Full parameters:

CreateTextImageToFile(String text, Font font, Color foreColor, Color backColor, int maxWidth, String outputFileName, TextImageWriteFileOption writeOption, System.Drawing.StringFormat stringFormat, ImageQualitySettings qualitySettings)

writeOption: Overwrite, IgnoreIfExists. Can be used to prevent a the image being recreated if it has already been created.

stringFormat: Can be used to set such settings as text alignment e.g.

StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;


qualitySettings: Provides many options to configure the quality of the image generated e.g. number of colors to be used, jpeg quality, text anti-alias method e.g.

ImageQualitySettings settings = new ImageQualitySettings(ImageType.Gif, 64);
settings.TextRenderingHint = TextRenderingHint.AntiAlias;



Please note, you can use CreateTextImage method rather than the CreateTextImageToFile. This works as above but generates the image into a Stream parameter rather than writing directly to a file.


TO DO: Write example of embedding a truetype font as a resource into a DLL and using that. Useful if you do not have permission to install fonts on a server.

Last edited Mar 10, 2007 at 10:50 AM by stebrennan, version 2

Comments

No comments yet.