Pages

Monday, March 2, 2009

Creating an image file based on plain text from AX

For the new version of Logica's electronic invoice handling module (eScan) I needed to create a tiff image file from plain text.

Here is a short example on how you can do that through CLR from X++:
static void createTiffFromText(Args _args)
{
FileName outputFileName = @'C:\Test\MyNewImage.tiff';
str sampleText = "My sample text...";
System.Drawing.Bitmap bitmap;
System.Drawing.Graphics graphics;
;
bitmap = new System.Drawing.Bitmap(220, 50);
graphics = System.Drawing.Graphics::FromImage(bitmap
graphics.FillRectangle(System.Drawing.Brushes::get_Yellow(), 0, 0, 220, 50);
graphics.DrawString(sampleText,
new System.Drawing.Font("Verdana", 18),
new System.Drawing.SolidBrush(System.Drawing.Color::get_Black()), 0 ,0);
bitmap.Save(outputFileName, System.Drawing.Imaging.ImageFormat::get_Tiff());
// Show the image
Winapi::shellExecute(outputFileName);
}