Solved

distance between two pixels using VB.

Posted on 2001-07-18
7
263 Views
Last Modified: 2010-08-05
Hi,
   I have a BW scanned image that is saved as a bmp, basically I want to figure out it's length by measuring the top-most black pixel and the bottom pixel.  How do I find these pixels?  I also would like to find the width at a certain number of inches, pixels, or whatever down the image.  How do I do this also?  I figure it would be easy if I started at the top left pixel and scaned row by row till I found a black one but I have no idea how to do this.  Can someone help me?

Thanks in Advance,
Aaron
0
Comment
Question by:Cide
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 150 total points
ID: 6296056
Point Method
     

Returns, as a long integer, the red-green-blue (RGB) color of the specifiedpoint on a Form or PictureBox. Doesn't supportnamed arguments.

Syntax

object.Point(x, y)

--
Use a loop something like this:

for y=0 to Picture1.height
  for x=0 to Picture1.width
    if Picture1.Point(x,y) = vbBlack then
      msgbox "Found it at x,y= " & x & "," & y, vbokonly
      y = Picture1.height ' force exit of the row loop
      exit for
    end if
  next x
next y

0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6296575
Hi!

Here's a file over the net for you:

Download...
http://www.planetsourcecode.com/upload/ftp/CODE_UPLOAD7488762000.zip

Description: I just made a couple changes to this.I am new at programming so this is my first shot so i hope i don't blow it:) This program lets you open a picture file and it tells you the height and width of the picture in pixels. I think this would come in very handy in making webpages so you'll know the exact dimensions of the pic. If it is really useless let me know. Thx

That's it!

glass cookie : )
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6297083
Note about rspahitz's code. Change the picbox's scalemode to pixels. It'll run about 225 (15x15) times faster that way. Also, you'll need a backwards loop to search up from the bottom. Same code, but with two changes:

for y=Picture1.height to 0 step -1

     y = 0 ' force exit of the row loop

KDL
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:KDivad
ID: 6297088
To get the width, just pick a row (second parameter of Point) to select points from and search across (inner For-Next loop). Then do the same on the same row but look backwards from the other end.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6299282
Thanks, KDivad, I forgot about the "bottom" and "right" request.
0
 

Author Comment

by:Cide
ID: 6299479
Wow works like a charm thanks guys!

Kdivad thnaks additionally for your extra help, went so much faster with your "tweaks".  If you want some points I can put then on a sperate question just ask me.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6299608
rspahitz,
We all have to forget something sometimes. Gives the rest of us a chance to brag a bit. <grin>

Cide,
Don't worry about it. I may need your help someday.

Later,
KDL
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question