
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Math
Public Class Form1

    Dim the_bitmap As Bitmap

    ' Current pixel being worked on
    Dim x As Integer
    Dim y As Integer
    Dim col As Color
    Dim id As Integer
    ' width and height of teh BMP
    Dim bmp_width As Integer
    Dim bmp_height As Integer
    ' File name
    Dim filename As String
    ' stuff
    Dim startid As Integer
    Dim locx As Integer
    Dim locy As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' doit()
    End Sub

    Public Sub doit()
        Dim a As New Bitmap("c:\12.bmp")
        Preview.Image = Image.FromHbitmap(a.GetHbitmap)
    End Sub


    Private Sub btn_browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_browse.Click

        bmpfd.CheckFileExists = True
        bmpfd.ShowDialog()
        txt_bmp.Text = bmpfd.FileName
        the_bitmap = New Bitmap(txt_bmp.Text)
        Preview.Image = Image.FromHbitmap(the_bitmap.GetHbitmap)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ended As Boolean
        rtbout.Text = ""
        x = 1
        y = 1
        locx = TXTx.Text
        locy = TXTy.Text
        startid = txtstartid.Text
        id = startid
        Do
            Application.DoEvents()
            col = the_bitmap.GetPixel(x, y)
            If col.R < 100 Then
                rtbout.Text = rtbout.Text & "g15.addpx(" & id & "," & x + locx & "," & y + locy & ")" & vbNewLine
                id = id + 1
            End If

            x = x + 1

            If x > the_bitmap.Width - 1 Then
                x = 1
                y = y + 1
            End If

            If y > the_bitmap.Height - 1 Then
                ended = True
            End If



        Loop Until ended = True

    End Sub
End Class
