473,651 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Scan a picture in a PictureBox ?

4 New Member
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 2501
Killer42
8,435 Recognized Expert Expert
What version of VB?
Oct 8 '07 #2
Anoosha
4 New Member
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 Recognized Expert Expert
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
8337
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 contents of the CD, at the moment i have a drop down drive menu that allows me to select the drive, i want to be able to put the CD in and then have i view only the CD contents, Ive considered just entering in my code D:\ but what happens if the...
4
15505
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 in at and so the result was:
10
9495
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 draw (but for specific uses). What I need to be able to do is import graphics and text and then move them around the background until they are where I want them and then export it out as an image file. The problem is that I need to be able to...
3
10463
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 show the picture in an imagecontrol, since the image is very large and I want to stretch it. But when I execute the following code:
1
9699
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 = "y1: " & y1
2
12396
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 code in the "real" project. In the "real" project, One part of the program saves multiple images and another part of the program moves the images to the appropriate directories based on user feedback.
2
16402
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 object, with g = pictureBox.CreateGraphic, and draw lines g.drawLines(....) But when saving the picture, the new picture have no lines, it is only a copy.
1
1879
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 name or control text would suit my needs. Regards Jeff
0
7239
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 pixels(1 To ubx, 1 To uby) As Long
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.