506
April 1st, 2008, 05:39 PM
Hello: I'm working with the drawing class and am having big time issues with slowness when using GetPixel and SetPixel. I found some great script online that I'm trying to work with:( http://www.codeproject.com/KB/vb/FastPixel.aspx?msg=2489348#xx2489348xx) and it basically locks up the bitmap and stores the pixels into an array to work with.
When using it, it works for some of my bitmaps...but bombs for others. this is the error I get:
Index was outside the boundws of the array(see ''it bombs on this line: ' to see exact line below).
I understand that the array isn't big enough but i don't understand why it works for some of my bitmaps and not others.
When I save my bitmaps, I save them as 24 bit rgb color 300 dpi. I don't know much about resolutions and what format is best to save them as.
Has anyone here has experience working with bitmaps and drawing class? I could sure use any dirrection..here.
thanks,
Proctor
Public Function GetPixel(ByVal x As Integer, ByVal y As Integer) As Color
If Not Me.locked Then
Throw New Exception("Bitmap not locked.")
Return Nothing
End If
If Me.IsAlphaBitmap Then
Dim index As Integer = ((y * Me.Width + x) * 4)
Dim b As Integer = Me.rgbValues(index)
Dim g As Integer = Me.rgbValues(index + 1)
Dim r As Integer = Me.rgbValues(index + 2)
Dim a As Integer = Me.rgbValues(index + 3)
Return Color.FromArgb(a, r, g, b)
Else
Dim index As Integer = ((y * Me.Width + x) * 3)
'it bombs on this line: Dim b As Integer = Me.rgbValues(index)
Dim g As Integer = Me.rgbValues(index + 1)
Dim r As Integer = Me.rgbValues(index + 2)
Return Color.FromArgb(r, g, b)
End If
End Function
When using it, it works for some of my bitmaps...but bombs for others. this is the error I get:
Index was outside the boundws of the array(see ''it bombs on this line: ' to see exact line below).
I understand that the array isn't big enough but i don't understand why it works for some of my bitmaps and not others.
When I save my bitmaps, I save them as 24 bit rgb color 300 dpi. I don't know much about resolutions and what format is best to save them as.
Has anyone here has experience working with bitmaps and drawing class? I could sure use any dirrection..here.
thanks,
Proctor
Public Function GetPixel(ByVal x As Integer, ByVal y As Integer) As Color
If Not Me.locked Then
Throw New Exception("Bitmap not locked.")
Return Nothing
End If
If Me.IsAlphaBitmap Then
Dim index As Integer = ((y * Me.Width + x) * 4)
Dim b As Integer = Me.rgbValues(index)
Dim g As Integer = Me.rgbValues(index + 1)
Dim r As Integer = Me.rgbValues(index + 2)
Dim a As Integer = Me.rgbValues(index + 3)
Return Color.FromArgb(a, r, g, b)
Else
Dim index As Integer = ((y * Me.Width + x) * 3)
'it bombs on this line: Dim b As Integer = Me.rgbValues(index)
Dim g As Integer = Me.rgbValues(index + 1)
Dim r As Integer = Me.rgbValues(index + 2)
Return Color.FromArgb(r, g, b)
End If
End Function