Problem Source: http://www.cnblogs.com/del/archive/2008/08/10/1071357.html#1282779
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) memo1: tmemo; {enter the text to save} combox1: tcombobox; {font} labelededit1: tlabelededit; {font size} character: tlabelededit; {page margin} labelededit3: tlabelededit; {Line spacing} button1: tbutton; label1: tlabel; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {initialization data} procedure tform1.formcreate (Sender: tobject); begin combobox1.items: = screen. fonts; combobox1.text: = 'ject '; labelededit1.text: = '12'; labelededit2.text: = '10'; labelededit3.text: = '4'; end; Procedure encode (Sender: tobject ); const filepath = 'C: \ temp \ word.bmp '; {path of the image to be saved} var STR: string; bit: tbitmap; page_edge: integer; {page margin variable} word_h, line_h: integer; {font height and line spacing} W, X, Y: integer; {text width and output position} I: integer; begin STR: = memo1.text; bit: = tbitmap. create; bit. canvas. font. name: = combobox1.text; bit. canvas. font. size: = strtointdef (labelededit1.text, 9); page_edge: = strtointdef (labelededit2.text, 0); word_h: = bit. canvas. textheight ('A'); line_h: = strtointdef (labelededit3.text, 0); {set page height} bit. height: = (word_h + line_h) * memo1.lines. count-line_h + page_edge * 2; W: = 0; X: = page_edge; Y: = page_edge; for I: = 0 to memo1.lines. count-1 do begin {set page width} If bit. canvas. textwidth (memo1.lines [I])> W then begin W: = bit. canvas. textwidth (memo1.lines [I]); bit. width: = W + page_edge * 2; end; {draw text} bit. canvas. textout (X, Y, memo1.lines [I]); {next line} Inc (Y, word_h + line_h); end; {save as image} bit. savetofile (filepath); bit. free; end.
Form file:
Object form1: tform1 left = 0 Top = 0 activecontrol = memo1 caption = #25226 #25991 #26412 #20445 #23384 #20026 #22270 #29255 clientheight = 274 clientwidth = 370 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate pixelsperinch = 96 textheight = 13 object label1: tlabel left = 242 Top = 7 width = 24 Height = 13 caption = #23383 #20307 end object memo1: tmemo left = 0 Top = 0 width = 234 Height = 274 align = alleft lines. strings = ('memo1') scrollbars = ssboth taborder = 0 explicitheight = 249 end object labelededit1: tlabelededit left = 240 Top = 76 width = 121 Height = 21 editlabel. width = 24 editlabel. height = 13 editlabel. caption = #23383 #21495 taborder = 1 end object button1: tbutton left = 242 Top = 227 width = 120 Height = 25 caption = #25226 #25991 #26412 #20445 #23384 #20026 #22270 #29255 taborder = 2 onclick = button1click end object combobox1: tcombobox left = 240 Top = 25 width = 120 Height = 21 itemheight = 13 taborder = 3 text = 'combox1' end object labelededit2: tlabelededit left = 240 Top = 120 width = 121 Height = 21 editlabel. width = 24 editlabel. height = 13 editlabel. caption = #36793 #36317 taborder = 4 end object labelededit3: tlabelededit left = 240 Top = 168 width = 121 Height = 21 editlabel. width = 24 editlabel. height = 13 editlabel. caption = #34892 #36317 taborder = 5 endend