Mega Code Archive

 
Categories / Delphi / Graphic
 

Convert Text to Image

Title: Convert Text to Image Question: A member needs a Text2Gif component for a web-application. There is simply one method: CreateGifFile(aText, aFullPath: string), that takes a string and writes a GIF-file to the disk that displays the text in the graphic format. Additional properties for font- size, font-type, color, maximal x- and y-pixel of the gif etc are necessary ... (automatic line-break is an important feature that should be covered !!!) Answer: Converting text to an imageToday I received my copy of Delphi 8, so I thought lets do this with D8. The output of this challenge needs to be a GIF file, so I first checked if the .NET framework supports this image-format. After experimenting for a while I came up with the following function:function GetImageCodecInfoForExtension(const aExt: string): ImageCodecInfo; var lCodecs: array of ImageCodecInfo; i: Integer; begin Result := nil; lCodecs := ImageCodecInfo.GetImageEncoders; for i := Low(lCodecs) to High(lCodecs) do if Pos(UpperCase(aExt), UpperCase(lCodecs[i].FilenameExtension)) 0 then begin Result := lCodecs[i]; Break; end; end;