How to Scan a picture in a PictureBox ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anoosha
    New Member
    • Oct 2007
    • 4

    How to Scan a picture in a PictureBox ?

    Dear Programmers I need your help,
    I have a PictureBox there I load A picture retrieved from Database.
    This so far good, but Now I want to scan the picture line by line horizontaly, to find which line of the picture that contains most pixels. How can I do that ?
    Many Thanx
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    What version of VB?

    Comment

    • Anoosha
      New Member
      • Oct 2007
      • 4

      #3
      Hi Killer.

      I use VB6.0 for this project.
      I read a picture in a picturebox. The picture is a Signature.
      I have 10 lines and I need to locate them there (on the Signature-Picture) which have the most pixels with a horizontaly direction. For that I scan the height of the picture, line by line. (I hope I am giving a clear view of what I am doing so far!)

      '---------------------------------------------
      Here I send U my codes. Each line I scan I get the black pixels which are continuously laid after each other(The signature is black on a white paper).
      Each time I find the segment I count the black pixels and then save it to an array, the next segment of the same line if bigger than the previous value is replaced.
      '------------------------------------------------------------------------------------------------------------------
      'I scan the height of the picture horizontaly and find the biggest value of black-pxls that are continuously laid,
      'after each other on a line, the first 10 line and store them in arrLines().
      'For the lines with height >=10, if their biggest value is bigger than the smallest value in the array, I replace.
      '------------------------------------------------------------------------------------------------------------------
      [CODE=vb] Dim X As Long, lW As Long, Y As Long, lH As Long, lPxl As Long
      Dim arrLines(0 To 9) As Long, arrHeight(0 To 9) As Long, arrTemp(0) As Long
      Dim nNumPxl As Integer, nCompare As Integer
      Dim nVal1 As Integer, nVal2 As Integer, nSmall As Integer, nIdx As Integer, i As Integer
      Dim nResult As Integer, nIdxResult As Integer

      lW = lPicWPxl
      lH = lPicHPxl
      nResult = 10000
      For Y = 0 To lH
      For X = 0 To lW
      lPxl = GetPixel(Pic_Ov erview.hdc, X, Y)
      If lPxl = 0 Then
      nNumPxl = nNumPxl + 1
      ' MsgBox nNumPxl
      Else
      If nNumPxl > 0 Then
      If Y < 10 Then 'The first 10 lines.
      nCompare = arrLines(Y)
      If nNumPxl > nCompare Then
      arrLines(Y) = nNumPxl
      End If
      nNumPxl = 0
      Else 'From Y>=10 compare the value with the smallest value in arrLines(), if the value bigger than the smallest replace it!
      nCompare = arrTemp(0)
      If nNumPxl > nCompare Then
      arrTemp(0) = nNumPxl
      End If
      nNumPxl = 0
      End If
      End If
      End If
      Next X
      If Y < 10 Then
      arrHeight(Y) = Y
      Else
      For nIdx = LBound(arrLines ) To (UBound(arrLine s) - 1)
      nVal1 = arrLines(nIdx)
      nVal2 = arrLines(nIdx + 1)
      If nVal2 < nVal1 Then
      nSmall = nVal2
      i = nIdx + 1
      Else
      nSmall = nVal1
      i = nIdx
      End If
      If nSmall < nResult Then
      nResult = nSmall
      nIdxResult = i
      End If
      Next nIdx
      If arrTemp(0) > nResult Then
      arrLines(nIdxRe sult) = arrTemp(0)
      arrHeight(nIdxR esult) = Y
      End If
      nResult = 10000
      arrTemp(0) = 0
      End If
      ' nNumPxl = 0
      Next Y
      '---------------------Set 10 lines!
      Line_GetPxl1.Y1 = arrHeight(0)
      Line_GetPxl1.Y2 = Line_GetPxl1.Y1
      Line_GetPxl1.Vi sible = True
      Line_GetPxl2.Y1 = arrHeight(1)
      Line_GetPxl2.Y2 = Line_GetPxl2.Y1
      Line_GetPxl2.Vi sible = True
      '
      '
      '-----------------------------------etc [/CODE]
      This solution is not accepted (by boss). According to him I need to find the direction of each pixel!
      I have seen on Internet its about MATLAB and very complicated math-calculation and transformation and so on....
      I am lost and I need help.
      Do U have any idea for my problem ?
      Thank U on forhand.
      /Anoosha


      Originally posted by Killer42
      What version of VB?
      Last edited by debasisdas; Oct 15 '07, 09:50 AM. Reason: Formatted using code tags.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        A pixel doesn't have a direction, just a colour.

        Anyway, I'll go through this at lunch time and see whether I can think of anything that might help (don't have time right now).

        Comment

        Working...