Mikecrosoft
02-02-2004, 09:21 AM
Hi all
I made this function to my own use, its a good function, the function returns a region following the BITMAP given, and the Exclude Color to make a irregular Region (Irregular Forms), the function works great if the window its a Fixed Size (even non fixed) the only detail its that the function its slow, so when I used it in a Resizable form on every call to this function the form resize turn slow too. So I'm searching a best way to make a region from a BMP. Or some ideas on how give more speed to my Region construction function.
Public Function MakeRegion(ByVal ShapeBitmap As Bitmap, ByVal ExcludeColor As Color) As Region
Dim pg As New Drawing2D.GraphicsPath
Dim i, j As Integer
For i = 0 To ShapeBitmap.Height - 1
For j = 0 To ShapeBitmap.Width - 1
If Not ShapeBitmap.GetPixel(j, i).Equals(ExcludeColor) Then
Dim tmpX As Integer = j
While Not j = ShapeBitmap.Width - 1 AndAlso Not ShapeBitmap.GetPixel(j, i).Equals(ExcludeColor)
j += 1
End While
pg.AddRectangle(New Rectangle(tmpX, i, j - tmpX, 1))
End If
Next
Next
pg.Dispose()
Return New Region(pg)
End Function
Thanks in advance
Mike
Soon I'll post a good sample of Irregular Forms.
I made this function to my own use, its a good function, the function returns a region following the BITMAP given, and the Exclude Color to make a irregular Region (Irregular Forms), the function works great if the window its a Fixed Size (even non fixed) the only detail its that the function its slow, so when I used it in a Resizable form on every call to this function the form resize turn slow too. So I'm searching a best way to make a region from a BMP. Or some ideas on how give more speed to my Region construction function.
Public Function MakeRegion(ByVal ShapeBitmap As Bitmap, ByVal ExcludeColor As Color) As Region
Dim pg As New Drawing2D.GraphicsPath
Dim i, j As Integer
For i = 0 To ShapeBitmap.Height - 1
For j = 0 To ShapeBitmap.Width - 1
If Not ShapeBitmap.GetPixel(j, i).Equals(ExcludeColor) Then
Dim tmpX As Integer = j
While Not j = ShapeBitmap.Width - 1 AndAlso Not ShapeBitmap.GetPixel(j, i).Equals(ExcludeColor)
j += 1
End While
pg.AddRectangle(New Rectangle(tmpX, i, j - tmpX, 1))
End If
Next
Next
pg.Dispose()
Return New Region(pg)
End Function
Thanks in advance
Mike
Soon I'll post a good sample of Irregular Forms.