Preparations:
Place a tpanel on the form; put a timage on the tpanel; three buttons are required.
In this example:
First version Code :
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; Panel1: tpanel; image1: timage; Procedure alert (Sender: tobject); Procedure button2click (Sender: tobject); Procedure alert (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} uses clipbrd; Procedure tform1.button1click (Sender: tobject); begin image1.left: = 0; image1.top: = 0; panel1.autosize: = true; image1.autosize: = true; image1.picture. loadfromfile ('C: \ temp \ test.bmp '); tbutton (sender ). caption: = 'import'; end; Procedure tform1.button2click (Sender: tobject); begin clipboard. assign (image1.picture); {put the image in image1 into the clipboard} {now you can paste it in the image software. You can use the Windows Image board to try} tbutton (sender ). caption: = 'copy'; end; Procedure tform1.button3click (Sender: tobject); var bit: tbitmap; {prepare to end the image from the clipboard with a tbitmap} X, Y: integer; begin bit: = tbitmap. create; bit. assign (Clipboard); {Get from clipboard} X: = panel1.width + panel1.left * 2; {X, Y is the position to be pasted on the form} y: = panel1.top; canvas. draw (X, Y, bit); {paste is drawn} bit. free; tbutton (sender ). caption: = 'pause'; end.
But nowProgramThere is also a vulnerability: if there is nothing in the clipboard, what should I paste? If the clipboard is not an image, how can I paste it?
In fact, we only use the tclipboard. hasformat function to determine whether the clipboard is an image.
Version 2 code:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; Panel1: tpanel; image1: timage; Procedure alert (Sender: tobject); Procedure button2click (Sender: tobject); Procedure alert (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} uses clipbrd; Procedure tform1.button1click (Sender: tobject); begin image1.left: = 0; image1.top: = 0; panel1.autosize: = true; image1.autosize: = true; image1.picture. loadfromfile ('C: \ temp \ test.bmp '); tbutton (sender ). caption: = 'import'; end; Procedure tform1.button2click (Sender: tobject); begin {If image1 does not have any image, do not copy it. Exit.} If image1.picture = nil then exit; clipboard. assign (image1.picture); tbutton (sender ). caption: = 'copy'; end; Procedure tform1.button3click (Sender: tobject); var bit: tbitmap; X, Y: integer; begin {if something in the current clipboard is not an image, exit.} if not clipboard. hasformat (cf_bitmap) Then exit; bit: = tbitmap. create; bit. assign (Clipboard); X: = panel1.width + panel1.left * 2; Y: = panel1.top; canvas. draw (X, Y, bit); bit. free; tbutton (sender ). caption: = 'pause'; end.
Now there is a new problem: the cf_bitmap constant represents the image. How does one represent other formats? How many formats can be used for clipboard?