Author: Tomas Rutkauskas
I have 3 Bitmaps. I copy BM2 on BM1. Then the problem: Copy a defined polygon from
BM3 (or BM2) into BM1. I only want to map the defined polygon into BM1 without
destroying any pixels outside the poly (within the rectangle).
Answer:
Here is one way you can try. It defines a polygon shaped clip region for the
destination bitmap, then copies the origin bitmap:
1 { ... }
2 var
3 pts: array of TPoint;
4 rgn: HRgn;
5 begin
6 SetLength(pts, 4);
7 pts[0] := Point(0, 0);
8 pts[1] := Point(50, 20);
9 pts[2] := Point(20, 50);
10 pts[3] := pts[0];
11 rgn := CreatePolygonRgn(pts[0], 4, Winding);
12 SelectClipRgn(bm1.Canvas.Handle, rgn);
13 bm1.Canvas.Copyrect(rect(0, 0, bm2.width, bm2.height),
14 bm2.canvas, rect(0, 0, bm2.width, bm2.height);
15 DeleteObject(rgn);
16 end;
17 { ... }
|