Pixel Scanning

Posts 1–7 of 7 · Page 1 of 1
Pixel Scanning
Hi guys so here is my code for pixel color scanning

Code:
Imports System.Drawing

Public Class TypeR
Dim ofd As New OpenFileDialog
Dim x As Integer = 0
Dim y As Integer = 0

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

ofd.InitialDirectory = ("C:\TypeR")
ofd.ShowDialog()
textbox3.Text = ofd.FileName
PictureBox2.ImageLocation = textbox3.Text
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
myx.Text = "0"
myy.Text = "0"
End If
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = speed.Text
Dim mydrawing As System.Drawing.Bitmap = System.Drawing.Bitmap.FromFile(ofd.FileName)
Dim thecolor As Color
thecolor = mydrawing.GetPixel(myx.Text, myy.Text)
r.Text = thecolor.R
g.Text = thecolor.G
b.Text = thecolor.B
myx.Text = myx.Text + 1
If myx.Text = mydrawing.Width Then
myy.Text = myy.Text + 1
myx.Text = 0

Else

End If
If myx.Text = mydrawing.Height - 1 And myy.Text = mydrawing.Width - 1 = True Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
Dim Myr As Integer = r.Text
Dim Myg As Integer = g.Text
Dim Myb As Integer = b.Text
PictureBox1.BackColor = Color.FromArgb(Myr, Myg, Myb)
If myy.Text = 30 Then
Timer1.Enabled = False
End If
End Sub


End Class
Now I want to add away to recognize numbers so every time a certain color of pixel is scanned it adds to a group then if that group is rite it sends the number to a text box so example
Code:
Dim sz(9) As String
        sz(0) = "0000110000001111000011001100110000110110000110110000110110000110011001100001
11100"
        sz(1) = "0000110000000110000001110000011110000000110000000110000000110000000110000000
11000000011000001111110"
        sz(2) = "0001111000011001100110000110000000110000001100000011000000110000001100000011
00000011111111"
        sz(3) = "0011111000110001100000000110000001100000111000000001100000000110000000110110
00110001111100"
        sz(4) = "0000001100000011100000111100001101100011001100110001100111111110000001100000
00110000000110"
        sz(5) = "0111111100110000000110000000110111000111001100000000110000000110110000110011
00110000111100"
        sz(6) = "0001111000011001100110000100110000000110111000111001100110000110110000110011
00110000111100"
        sz(7) = "0111111110000000110000000110000001100000011000000110000001100000011000000110
00000011000000"
        sz(8) = "0001111000011001100110000110011001100001111000011001100110000110110000110011
00110000111100"
        sz(9) = "0001111000011001100110000110110000110011001110001110110000000110010000110011
00110000111100"

        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim nLine As Integer = 0
        Dim nGroup As Integer = 0
        Dim szGroup(5) As String
        Dim szTemp As String = ""
        Dim bmp As Bitmap = pic.Image.Clone
        For y = 11 To pic.Height - 10 Step 1
            nLine = 1
            nGroup = 0
            For x = 7 To pic.Width - 9 Step 1
                If bmp.GetPixel(x, y).ToArgb = Color.White.ToArgb Then
                    szTemp = szTemp & "0"
                ElseIf bmp.GetPixel(x, y).ToArgb = Color.Black.ToArgb Then
                    szTemp = szTemp & "1"
                End If
                If nLine = 9 Then

                    szGroup(nGroup) = szGroup(nGroup) & szTemp
                    szTemp = ""
                    nLine = 1
                    nGroup += 1
                Else
                    nLine += 1
                End If
            Next
        Next
        For x = 0 To 5
            For y = 0 To 9
                If szGroup(x) = sz(y) Then
                    rtb.Text = rtb.Text & y.ToString
                End If
            Next
        Next
that is not mine its just what I want to add to my project but I am kinda lost at this point on where and how to add those function to my code
@Gbstar:
Code:
        Dim OFD As New OpenFileDialog
        Dim WhitePixels As Integer = 0
        Dim BlackPixels As Integer = 0
        If Not OFD.ShowDialog() = DialogResult.Cancel Then
            Dim pic As New Bitmap(OFD.FileName)
            Dim Black As Color = Color.Black
            Dim White As Color = Color.White
            For x As Integer = 0 To pic.Width - 1
                For y As Integer = 0 To pic.Height - 1
                    If (pic.GetPixel(x, y).ToArgb = Black.ToArgb) Then
                        BlackPixels += 1
                    End If
                    If (pic.GetPixel(x, y).ToArgb = White.ToArgb) Then
                        WhitePixels += 1
                    End If
                Next
            Next
        End If
        MessageBox.Show("White Pixels: " & WhitePixels & Environment.NewLine & "Black Pixels: " & BlackPixels)
Paste this code on a button's click event or some other event but not in a Timer.
nice code but not the one I need already knew that one what I need is adding the white & black pixels on a line so like this

00001110000
00011110000
00111110000
01101110000 Witch would equal 1 in a text box, the string would look like this "00001110000(next line)00011110000(next line) etc
01001110000
00001110000
00001110000
11111111110

I have seen this as text recognition in visual basic but never had to actually use it till now if you or any one have a better tutorial for text recognition *text from a picture* then could you point me to it thanks
Quote Originally Posted by Gbstar View Post
nice code but not the one I need already knew that one what I need is adding the white & black pixels on a line so like this

00001110000
00011110000
00111110000
01101110000 Witch would equal 1 in a text box, the string would look like this "00001110000(next line)00011110000(next line) etc
01001110000
00001110000
00001110000
11111111110

I have seen this as text recognition in visual basic but never had to actually use it till now if you or any one have a better tutorial for text recognition *text from a picture* then could you point me to it thanks
I don't understand what you are trying to do. What are those 0's and 1's. If you can explain it properly, I might be able to help you better.
ok the pixels are added to a string that string is compared to a number if those pixels added to the sting match the number pixel count then that is added to a text box or a message box if yud like like I said

the number 1 would look like this "0000111000000011110000001111100000110111000001001 110000000011100000000111000011111111110" now in the picture since white is counted as 0 and black is counted as 1 the picture (is a 1) in pixels would look like this
00001110000
00011110000
00111110000
01101110000
01001110000
00001110000
00001110000
11111111110

hope you understand that and read the first post second code its what I want to do but I don't understand it
Got it don't bother with it anymore
Alright. Closed.
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us