473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Oct 8 '07 #1
3 2489
Killer42
8,435 Expert 8TB
What version of VB?
Oct 8 '07 #2
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.
'------------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1.   Dim X As Long, lW As Long, Y As Long, lH As Long, lPxl As Long
  2.   Dim arrLines(0 To 9) As Long, arrHeight(0 To 9) As Long, arrTemp(0) As Long
  3.   Dim nNumPxl As Integer, nCompare As Integer
  4.   Dim nVal1 As Integer, nVal2 As Integer, nSmall As Integer, nIdx As Integer, i As Integer
  5.   Dim nResult As Integer, nIdxResult As Integer
  6.  
  7.   lW = lPicWPxl
  8.   lH = lPicHPxl
  9.   nResult = 10000
  10.   For Y = 0 To lH
  11.     For X = 0 To lW
  12.       lPxl = GetPixel(Pic_Overview.hdc, X, Y)
  13.       If lPxl = 0 Then
  14.         nNumPxl = nNumPxl + 1
  15. '        MsgBox nNumPxl
  16.       Else
  17.         If nNumPxl > 0 Then
  18.           If Y < 10 Then                'The first 10 lines.
  19.             nCompare = arrLines(Y)
  20.             If nNumPxl > nCompare Then
  21.               arrLines(Y) = nNumPxl
  22.             End If
  23.             nNumPxl = 0
  24.           Else                          'From Y>=10 compare the value with the smallest value in arrLines(), if the value bigger than the smallest replace it!
  25.             nCompare = arrTemp(0)
  26.             If nNumPxl > nCompare Then
  27.               arrTemp(0) = nNumPxl
  28.             End If
  29.             nNumPxl = 0
  30.           End If
  31.         End If
  32.       End If
  33.     Next X
  34.     If Y < 10 Then
  35.       arrHeight(Y) = Y
  36.     Else
  37.       For nIdx = LBound(arrLines) To (UBound(arrLines) - 1)
  38.         nVal1 = arrLines(nIdx)
  39.         nVal2 = arrLines(nIdx + 1)
  40.         If nVal2 < nVal1 Then
  41.           nSmall = nVal2
  42.           i = nIdx + 1
  43.         Else
  44.           nSmall = nVal1
  45.           i = nIdx
  46.         End If
  47.         If nSmall < nResult Then
  48.           nResult = nSmall
  49.           nIdxResult = i
  50.         End If
  51.       Next nIdx
  52.       If arrTemp(0) > nResult Then
  53.         arrLines(nIdxResult) = arrTemp(0)
  54.         arrHeight(nIdxResult) = Y
  55.       End If
  56.       nResult = 10000
  57.       arrTemp(0) = 0
  58.     End If
  59. '    nNumPxl = 0
  60.   Next Y
  61. '---------------------Set 10 lines!
  62.   Line_GetPxl1.Y1 = arrHeight(0)
  63.   Line_GetPxl1.Y2 = Line_GetPxl1.Y1
  64.   Line_GetPxl1.Visible = True
  65.   Line_GetPxl2.Y1 = arrHeight(1)
  66.   Line_GetPxl2.Y2 = Line_GetPxl2.Y1
  67.   Line_GetPxl2.Visible = True
  68. '
  69. '
  70. '-----------------------------------etc 
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


What version of VB?
Oct 15 '07 #3
Killer42
8,435 Expert 8TB
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).
Oct 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jeff | last post by:
Hiya, Im currently in the process of developing a picture browser, I want it to run off a CD, basically I have 2 questions for the group. The first is how do I get the program to only view the...
4
by: Chris | last post by:
Hi, I am trying to set the position of a picture inside a picturebox with the folowing code: pctOutput.Picture = LoadPicture(App.Path & "\picture.bmp", , , , ) I didn't know what to fill...
10
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel...
3
by: Sandra Setz | last post by:
Hi, Is it possible to assign the Picture property of a picturebox to the Picture property of an image control? I use an invisble picturebox to make some changes to a picture, but I want to...
1
by: Dennis | last post by:
Hello, Ive to draw a line on a picture i used this code: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x1 = z.X y1 = z.Y lbl3 = "x1: " & x1 lbl4...
2
by: Bill N. | last post by:
Using VB .Net 2003 Standard Edition. This simple form has a "File in Use" problem while the executable is running. Created this simple program to make sure that I hadn't done something in my...
2
by: Michael Lehar | last post by:
Hallo I have a pictureBox with a picture loaded from file, then I draw some lines on the picture, and then I want to save the new picture. Befor I can draw lines I have to create a Graphics...
1
by: Jeff Williams | last post by:
I have several picture boxes on a form. I want to be able to drag pictures to this picture box. On the Drop how can I tell which picture box I am dropping the picture on. Te picture Box control...
0
debasisdas
by: debasisdas | last post by:
Add two picture boxes to a form. Set the ScaleMode property of both the pictureboxes to 3-Pixels. General declaration -------------------------------- Const ubx = 1000 Const uby = 500 Dim...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.