Board index » delphi » Draw filled polygon

Draw filled polygon

Hi,

Im trying to draw a polygon that is filled with a bitmap
and I want to avoid Floodfill(...)

I tried the following code, but it doesnt work.
Is SelectClipRgn for the bitmap wrong?

procedure TForm1.Button1Click(Sender: TObject);
var r: Array of TPoint;
    rhandle: Hrgn;
begin

SetLength(r, 4);
r[0].x := 0;
r[0].y := 0;
r[1].x := 100;
r[1].y := 50;
r[2].x := 100;
r[2].y := 100;
r[3].x := 50;
r[3].y := 100;
rHandle := CreatePolygonRgn(r[0], High(r) + 1, Winding);
SelectClipRgn(Image2.Picture.Bitmap.Canvas.Handle, rHandle);
BitBlt(Paintbox1.Canvas.Handle, 123, 123, 321, 321,
Image2.Picture.Bitmap.Canvas.Handle, 0, 0, SrcCopy);
DeleteObject(rHandle);

end;

Many thanks.

 

Re:Draw filled polygon


Quote
In article <930cmh$s...@bornews.inprise.com>, Steffan Bansemer wrote:
> rHandle := CreatePolygonRgn(r[0], High(r) + 1, Winding);

rHandle := CreatePolygonRgn(r, High(r) + 1, Winding);

It takes an array you've given it an index into the array.

Gordon

ASP Developer Member http://www.asp-shareware.org/

Re:Draw filled polygon


Quote
> rHandle := CreatePolygonRgn(r, High(r) + 1, Winding);

> It takes an array you've given it an index into the array.

I dont know why, but
rHandle := CreatePolygonRgn(r[0], High(r) + 1, Winding);

should (must) be right.

Re:Draw filled polygon


Quote
In article <930fk5$s...@bornews.inprise.com>, Steffan Bansemer wrote:
> I dont know why, but
> rHandle := CreatePolygonRgn(r[0], High(r) + 1, Winding);

> should (must) be right.

Sorry, with a dynamic array you're correct, I should have looked
closer.

The region has to be in the *destination* dc (the paintbox) before
drawing.

Gordon

ASP Developer Member http://www.asp-shareware.org/

Re:Draw filled polygon


Steffan Bansemer schrieb:

Quote
> Hi,

> Im trying to draw a polygon that is filled with a bitmap
> and I want to avoid Floodfill(...)

> I tried the following code, but it doesnt work.
> Is SelectClipRgn for the bitmap wrong?

> procedure TForm1.Button1Click(Sender: TObject);
> var r: Array of TPoint;
>     rhandle: Hrgn;
> begin

> SetLength(r, 4);
> r[0].x := 0;
> r[0].y := 0;
> r[1].x := 100;
> r[1].y := 50;
> r[2].x := 100;
> r[2].y := 100;
> r[3].x := 50;
> r[3].y := 100;

> rHandle := CreatePolygonRgn(r[0], High(r) + 1, Winding);
> SelectClipRgn(Image2.Picture.Bitmap.Canvas.Handle, rHandle);
> BitBlt(Paintbox1.Canvas.Handle, 123, 123, 321, 321,
> Image2.Picture.Bitmap.Canvas.Handle, 0, 0, SrcCopy);
> DeleteObject(rHandle);

> end;

> Many thanks.

You can work via Windows API.
It handles also Islands.

Procedure FillPolyPolygon(TheDraw:TCanvas;Path:TXYPolyPointList);
 Var i,j:Integer;
 Begin
 TheDraw.Brush.Color:=...
 TheDraw.Style:=...
 SetGraphicsMode(TheDraw.Handle,gm_advanced);
 BeginPath(TheDraw.Handle);
 For i :=1 to Path.MaxPolygon do with Path.Polygons[i] do
  For j:=1 to MaxPoint do with Points[j] do
     If j=1 then
      MoveTo(x,y)
     else
      LineTo(X,Y);
 EndPath(TheDraw.Handle);
 FillPath(TheDraw.Handle);
 AbortPath(TheDraw.Handle);
 End;

Have Fun Alex

Other Threads