(* //
Title: Make a picture of the picture
Description: Applicable to making complex irregularities
Design: zswang
Support: wjhu111@21cn.com
Date: 2004-03-10
// *)
(* / / ================================================================================================================================================================================ ===============================
Design Idea: ~~
It is a scan for the canvas and one line ~~
For pixels that are not transparent, they see a line segment ~~
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─────────────────────
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
────────────────
Use these line segments into irregular areas ~~
The line segment is to find the starting position and the end position.
The combination area is the time-spent place ~~
Reduce the frequency of the combination area to improve the speed of operation ~~
The combination of line segments is more than the point combination ~~
============================================================================================================================================================================================================= ========================== // *)
Function graphictorgn (Mgraphic: Tgraphic; MTRANSPOINT: TPOINT): HRGN;
VAR
I, J: Integer;
vStart: integer;
Vhandle: hrgn;
VTRANSCOLOR: TCOLOR;
Begin
Result: = 0;
IF NOT ASSIGNED (MGRAPHIC) THEN EXIT
Result: = CreateRectrGN (0, 0, 0, 0);
With Tbitmap.create Do Try
Width: = mgraphic.width;
Height: = mgraphic.height;
Canvas.draw (0, 0, mgraphic);
VTRANSCOLOR: = Canvas.pixels [MTRANSPOINT.X, MTRANSPOINT.Y];
For i: = 0 to Height - 1 Do Begin
vStart: = 0;
For j: = 0 to width do beginif (canvas.pixels [j, i] <> vTranscolor) and (j IF vStart <0 THEN vStart: = j Else Else if vStart> = 0 THEN Begin vhandle: = CreateRectrGN (vStart, i, J, I 1); Try Combinergn (Result, Result, Vhandle, RGN_OR); Finally DeleteObject (vhandle); END; vStart: = -1; END; END; END; Finally FREE; END; End; {graphictorgn} // esample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR VRGN: hrgn Begin Borderstyle: = bsnone; Image1.left: = 0; Image1.top: = 0; VRGN: = graphictorgn (image1.picture.graphic, point (0, 0)); Try SetwindowRgn (Handle, VRGN, TRUE); Finally DeleteObject (VRGN); END; END;