Speed on crop

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
Hello,
This is to find the first darkest pixel, in order to crop a image, but it's too slow.
Is there a way to speed this?

PHP:
        Dim bmp As Bitmap = im
        Dim wth As Integer = 0
        Dim hgh As Integer = 0
        Dim newpoint As Drawing.Point
        Dim aL As Integer = 0
        Dim aC As Integer = 0

        'FROM SIDE
        For wth = 0 To bmp.Width - 1
            newpoint.X = wth
            For hgh = 0 To bmp.Height - 1
                newpoint.Y = hgh
                Dim mycolor As Color = DirectCast(bmp, Bitmap).GetPixel(newpoint.X, newpoint.Y)
                If (mycolor.B.ToString < 100) Then
                    aL = wth
                    Exit For
                End If
            Next
            If (aL <> 0) Then
                Exit For
            End If
        Next

        'FROM TOP
        For hgh = 0 To bmp.Height - 1
            newpoint.Y = hgh
            For wth = 0 To bmp.Width - 1
                newpoint.X = wth
                Dim mycolor As Color = DirectCast(bmp, Bitmap).GetPixel(newpoint.X, newpoint.Y)
                If (mycolor.B.ToString < 100) Then
                    aC = hgh
                    Exit For
                End If
            Next
            If (aC <> 0) Then
                Exit For
            End If
        Next

Thanks
 
Search for "vb.net lockbits", this method is very fast (and some more advanced than GetPixel/SetPixel).
 
Back
Top