In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, Dib, stdctrls, extctrls; Type tform1 = Class (tform) dxpaintbox1: bytes; button1: tbutton; button2: tbutton; colorbox1: tcolorbox; colorbox2: tcolorbox; Procedure Recipe (Sender: Taobao); Procedure Recipe (Sender: tobject ); procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} const STR = 'chun'; var Dib, dib1, dib2: tdib; Procedure tform1.formcreate (Sender: tobject); const imgpath1 = 'C: \ temp \ dx.jpg '; begin Dib: = tdib. create; dib1: = tdib. create; dib2: = tdib. create; DiB. loadfromfile (imgpath1); dxpaintbox1.clientwidth: = DiB. width; dxpaintbox1.clientheight: = DiB. height; dxpaintbox1.dib. assign (DIB); dib1.assign (DIB); dib2.setsize (DiB. width, DiB. height, 24); dib2.canvas. brush. style: = bsclear; dib2.canvas. font. name: = 'simhei '; dib2.canvas. font. size: = 90; dib2.canvas. font. style: = [fsbold]; colorbox1.selected: = clblack; colorbox2.selected: = clyellow; end; Procedure tform1.formdestroy (Sender: tobject); begin DiB. free; dib1.free; dib2.free; end; Procedure tform1.button1click (Sender: tobject); begin dib1.assign (DIB); dib2.fill (colorbox1.selected); dib2.canvas. font. color: = colorbox2.selected; dib2.canvas. textout (0, 0, STR); dib1.drawalphamask (dib2, dib1, 0, 0, DiB. width, DiB. height, 0, 0); dxpaintbox1.dib. assign (dib1); dxpaintbox1.repaint; end; Procedure tform1.button2click (Sender: tobject); begin dib1.assign (DIB); dib2.fill (colorbox2.selected); dib2.canvas. font. color: = colorbox1.selected; dib2.canvas. textout (0, 0, STR); dib1.drawalphamask (dib2, dib1, 0, 0, DiB. width, DiB. height, 0, 0); dxpaintbox1.dib. assign (dib1); dxpaintbox1.repaint; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 142 clientwidth = 226 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate ondestroy = formdestroy pixelsperinch = 96 textheight = 13 object dxpaintbox1: tdxpaintbox left = 8 Top = 8 width = 81 Height = 73 autostretch = false center = false keepaspect = false stretch = false viewwidth = 0 viewheight = 0 end object button1: tbutton left = 143 Top = 78 width = 75 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object button2: tbutton left = 143 Top = 109 width = 75 Height = 25 caption = 'button2' taborder = 1 onclick = button2click end object colorbox1: tcolorbox left = 143 Top = 8 width = 81 Height = 22 itemheight = 16 taborder = 2 end object colorbox2: tcolorbox left = 143 Top = 36 width = 81 Height = 22 itemheight = 16 taborder = 3 endend