Drawing on the TIMAGE control

zhaozj2021-02-16  45

Drawing translations on TIMAGE control: I can see the mountain today

The TIMAGE class provides a Canvas property to draw you on the image of Image. Image changes will become part of this image saved. If you copy the changed image to the clipboard or save this image as a file, your change will become part of this image. A small program code here is used to draw an arrow on an Image.

Const tpoint arrow1 [] = {{80, 105}, {106, 66}, {80, 87}, {94, 98}}; image1-> canvas-> pen-> color = CLBLUE; image1-> canvas-> pen -> width = 3; image1-> canvas-> moveto (arrow1 [0] .x, arrow1 [0] .y; image1-> canvas-> lineto (arrow1 [1] .x, arrow1 [1] .y ); Image1-> canvas-> moveto (arrow1 [0] .x, arrow1 [0] .y; image1-> canvas-> lineto (arrow1 [2] .x, arrow1 [2] .y); image1 > Canvas-> MoveTo (arrow1 [0] .x, arrow1 [0] .y; image1-> canvas-> lineto (arrow1 [3] .x, arrow1 [3] .y);

Note: You can only use its Canvas properties when you use a Bitmap type, a graphic of the TIMAGE control. If it contains an icon or a chair file, you can't use its Canvas to draw. TiImage's read-only method Getcanvas confirms the reason for this.

// Transform functions for C code Tcanvas * TIMAGE:: Getcanvas () {graphics :: tbitmap * bitmap

IF (Picture-> graphic == null) {bitmap = new graphics :: tbitmap bitmap-> width = width; bitmap-> height = height;

/ / The new bitmap is assigned to the Graphic property. This call // TPICTURE write method setgraphic. Setgraphic Implement bitmap assignment, // is equivalent to calling Picture-> graphic-> assign (Bitmap); Picture-> graphic = bitmap ;

/ / Delete the temporary bitmap pointer. Because the assignment of the bitmap is over, the content of the bitmap has been saved in Picture-> Graphic delete Bitmap;}

IF (/ * picture-> graphic is a Tbitmap type object * /) return picture-> bitmap-> canvas; else throw einvalidoperty (/ * throw an exception * /);}

Note that if the Picture property is empty, you will create a new Bitmap object on the painting. If a bitmap has been loaded, then TIMAGE:: GetCanvas just returns the Canvas property of this bitmap. If Picture Is an icon or a chair file, the program will throw an exception.

转载请注明原文地址:https://www.9cbs.com/read-28279.html

New Post(0)