Fill a PNG with a gradient using path

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I'm trying to use a gradient on a PNG file that is one solid color (the shape in the PNG is), but I'm getting "Parameter is not valid". I just saw that PathPoints is read only, so I'm trying to figure out how to add points to a path. Is this possible, and how can I do it? Here's an example of the image I want to fill.
1329149929_4224ee059f.jpg


It's all one color, so I'm grabbing that color with the Picturebox MouseDown event and then searching for each pixel with that color. Here's my code.

VB.NET:
For x = 0 To PictureBox1.Image.Width - 1
            pt.X = x
            For y = 0 To PictureBox1.Image.Height - 1
                pt.Y = y
                color2 = DirectCast(PictureBox1.Image, Bitmap).GetPixel(pt.X, pt.Y)
                If color2 = mycolor Then
                    ListBox1.Items.Add(pt.X & "," & pt.Y)
                End If
            Next
        Next
        For xp = 0 To ListBox1.Items.Count - 1
            Dim ptstring As String = ListBox1.Items.Item(xp)
            Dim ptstringsplit() As String = ptstring.Split(",")
            pt2.X = ptstringsplit(0)
            pt2.Y = ptstringsplit(1)
        Next
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.FillPath(Brushes.LightSalmon, pth)
        PictureBox1.Image = bmp
        PictureBox1.Refresh()
 
You add points to the GraphicsPath by using the Add... methods, they have all the similarity with the Graphics class Draw... methods, but will add shapes to the path instead of drawing them if you see the connection. In this case you could check each pixel and add 1x1 rectangles to the path.
 
Back
Top