Board index » delphi » Polygon problem

Polygon problem

Whats the best way:
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 rec).

Thanks Chris

 

Re:Polygon problem


Quote
In article <3958B11F.5FB81...@gruppenhaus.de>, Christoph Merten wrote:
> Date: Tue, 27 Jun 2000 15:50:23 +0200
> From: Christoph Merten <chr...@gruppenhaus.de>
> Newsgroups: borland.public.delphi.graphics
> Subject: Polygon problem

> Whats the best way:
> 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 rec).

> Thanks Chris

Here is one way you can try, it defines a polygon shaped clip region
for the destination bitmap, then copies the origin bitmap:

..
var pts: array of TPoint;
    rgn: HRgn;
begin
  SetLength(pts,4);
  pts[0]:=Point(0,0);
  pts[1]:=Point(50,20);
  pts[2]:=Point(20,50);
  pts[3]:=pts[0];
  rgn:=CreatePolygonRgn(pts[0],4,Winding);
  SelectClipRgn(bm1.Canvas.Handle,rgn);
  bm1.Canvas.Copyrect(rect(0,0,bm2.width,bm2.height), bm2.canvas,      
        rect(0,0,bm2.width,bm2.height);
    DeleteObject(rgn);
end;
..

Renate Schaaf
Delphi Page:
http://www.xmission.com/~renates/delphi.html

Re:Polygon problem


Quote
Renate Schaaf wrote:
> Here is one way you can try, it defines a polygon shaped clip region
> for the destination bitmap, then copies the origin bitmap:

> ..
> var pts: array of TPoint;
>     rgn: HRgn;
> begin
>   SetLength(pts,4);
>   pts[0]:=Point(0,0);
>   pts[1]:=Point(50,20);
>   pts[2]:=Point(20,50);
>   pts[3]:=pts[0];
>   rgn:=CreatePolygonRgn(pts[0],4,Winding);
>   SelectClipRgn(bm1.Canvas.Handle,rgn);
>   bm1.Canvas.Copyrect(rect(0,0,bm2.width,bm2.height), bm2.canvas,
>         rect(0,0,bm2.width,bm2.height);
>     DeleteObject(rgn);
> end;
> ..

Thanks a lot! This works good - and simple!

Ciao Chris

Other Threads