PDA

Click to See Complete Forum and Search --> : Fill a Shape


TB
Feb 11th, 2001, 11:27 AM
Hi!

How can I fill out a polygon with a color.
When I know the outline or the corner points of a polygon, so how can I get all pixels that are inside the shape.

I tried to move along the outline till I reach the center of the shape but I had a lot of problems.

Thank you for any help.
Using VB 6.0

Fox
Feb 11th, 2001, 12:05 PM
A simple way is drawing the polygon using the API...


'Open a new VB project and add this code
'to the general section:

'Types
Private Type tCoord2D
x As Long
y As Long
End Type

'Declares
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As tCoord2D, ByVal nCount As Long) As Long

'Now add this to the Form_MouseDown event:
Dim Points(2) As tCoord2D

'Setup form (You can put this in
'Form_Load or directly edit the props)
With Me
.ScaleMode = 3

.BackColor = 0

.ForeColor = RGB(128, 0, 255)
.FillColor = RGB(128, 0, 255)
.FillStyle = 0

.Cls
End With

'Setup poylgon with 3 corners
Points(0).X = X
Points(0).Y = Y

Points(1).X = X + 100
Points(1).Y = Y + 50

Points(2).X = X + 50
Points(2).Y = Y + 100

'Draw the polygon
Polygon Me.hdc, Points(0), 3

TB
Feb 11th, 2001, 12:09 PM
Thanks!

But how can I fill the shape with a texture(from a Bitmap) or with a gradient fill?

Fox
Feb 11th, 2001, 01:27 PM
Thus you should use D3D... look at the D3D demo on my website which shows you how to draw a gradient-colored triangle (and rotate it ;))

Arcom
Feb 11th, 2001, 04:04 PM
Or, you can create a region, select it into device context and then fill it with anything you want...

If you want (or if you are not familiar with the Windows API), I can make a sample app to demonstrate this.