Results 1 to 5 of 5

Thread: Fill a Shape

  1. #1

    Thread Starter
    Lively Member TB's Avatar
    Join Date
    Feb 2001
    Location
    Austria
    Posts
    106

    Question

    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
    mojo

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    A simple way is drawing the polygon using the API...

    Code:
    '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

  3. #3

    Thread Starter
    Lively Member TB's Avatar
    Join Date
    Feb 2001
    Location
    Austria
    Posts
    106

    Cool Texture

    Thanks!

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

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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 )

  5. #5
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width