How to Convert a bitmap from grayscale to pure Black and White

inotec

New member
Joined
Jun 1, 2007
Messages
3
Programming Experience
5-10
I, can any one help me. I want to convert a image from grayscale to pure Black and White. Does anyone knows de matrix to convert fron graysclae to B&W or a way to do it.

Best Regards

INOTEC
 
VB.NET:
Something I wrote up for my project, enjoy.

    Public Function BlackWhiteFilter(ByVal bp As Bitmap)


        Dim colorBlack As New Color
        Dim colorWhite As New Color
        Dim pixels As New ArrayList
        Dim x As Integer, y As Integer
        Dim size As New Size(200, 40)
        Dim imageSize As New Size(200, 40)
        Dim PixelX As Integer
        Dim PixelY As Integer

        colorBlack = Color.Black
        colorWhite = Color.White


        'Convert to black and white
        For x = PixelX - CInt(size.Width) To PixelX + CInt(size.Width)
            For y = PixelY - CInt(size.Height) To PixelY + CInt(size.Height)

                If (x > 0 And x < imageSize.Width) And (y > 0 And y < imageSize.Height) Then

                    Dim splitARGB As String()
                    Dim colR As String
                    splitARGB = Split(BP.GetPixel(x, y).ToString(), ",")
                    colR = Replace(splitARGB(1), " R=", "")

                    If colR < 200 Then
                        BP.SetPixel(x, y, colorBlack)
                    Else
                        BP.SetPixel(x, y, colorWhite)
                    End If

                End If
            Next
        Next
 
Thanks jperks1985.

The code is good, but it takes to much time to convert de image. I need something faster, like a ColorMatrix conversion. I want to convert a image frame from a webcam and convert it to B&W on the fly.

But thank you any way.
Best Regards
Inotec
 
Thanks, but it's for grayscale and negative, doesn’t have de colormatrix for Black and White.

Best Regards

Inotec
 
Back
Top