Searching a Best function (Regions)

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.

Snail1985
02-02-2004, 01:38 PM
I had to do the same thing! although I found a pure api solution which loaded the bitmap into a DeviceContext and the used the api GetPixel Command! This is all very well but as you said it's very slow for larger images (I wouldn't use it for images more than 100 x 100)! However I started a thread asking pretty much the same question and someone told me about the getdibits function! basically instead of calling the GetPixel function you load all of the bits into a specific structure and then loop through this structure using much the same method as before. I havn't actually tested this as I sort of lost inerest after a relatively short while but it's worth a go!
Snail

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum