picture fill in vb.net

tonton

New member
Joined
Jan 6, 2003
Messages
2
Location
Hungary
Hello everybody!

I need some help with VB .net.I want to load a drawning into a picture box and i want to fill it with different colours.To be more specific ,the drawning is a country map, and each county sould have a different colour.The problem is that i dont know how to do this in .NET.(I could do this in vb 6)

So if you can help me please to do this(or, how can i use floodfill or extfloodfill in .NET?)

thanx

Tonton
 
When you paint in to a picture box, you use a Graphics object. You get this with the CreateGraphics method of the picturebox, or if youre handling the Paint event of it, you will receive a graphics object as a member of one of the parameters.

There is no GDI+ method for performing a floodfill, so youll have to resort to calling the API to do this. Youll need to use the GetHdc and ReleaseHdc methods of the graphics object around the call.
 
HI

This code paints a part of a picture boxs bacground picture but when something hides or i move a windows to the front of the picture ,everything what i did disapears. I cant use repaint it in the paint event.But i want to save this painted picture into an another picture.

The code:

Code:
Private Sub Feltolt(ByVal XKoordinata, ByVal YKoordinata, ByVal R, ByVal G, ByVal B)
        Dim hDC, hBrush As IntPtr
        Dim Grafika As Graphics = Terkep.CreateGraphics()
        Dim Szin As Color = CType(Terkep.Image, Bitmap).GetPixel(XKoordinata, YKoordinata)
        Dim Gdi_Szin As Color = Color.FromArgb(0, Szin.B, Szin.G, Szin.R)

        Try
            hDC = Grafika.GetHdc()

            hBrush = CreateSolidBrush(Color.FromArgb(0, R, G, B).ToArgb())

            Dim Last As IntPtr = SelectObject(hDC, hBrush)
            ExtFloodFill(hDC, XKoordinata, YKoordinata, Gdi_Szin.ToArgb(), FloodFillSurface)
            SelectObject(hDC, Last)
            DeleteObject(hBrush)
        Catch E As Exception
            Throw (E)
        Finally
            Grafika.ReleaseHdc(hDC)
            Grafika.Dispose()
        End Try
    End Sub

thanks
 
Last edited by a moderator:
You could create an offscreen bitmap I suppose, and do your painting in there. Then the offscreen bitmap will save what youve done and not get erased. If you then assign that bitmap to the picturebox via the .image property, it will display it and it wont get erased. Heres an example:

Code:
        Dim b As Bitmap = New Bitmap(100, 100)
        Dim g As Graphics = Graphics.FromImage(b)

        g.DrawEllipse(Pens.Red, PictureBox1.ClientRectangle)

        PictureBox1.Image = b

You could then use b.Save("c:\temp.bmp") to save it to disk.
 
Back
Top