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
Solved

Figure Out Percentages

Posted on 2010-11-25
8
315 Views
Last Modified: 2012-05-10
I am hoping that the experts can help me out with some calculations.

I am scanning an image (using EZTwain Pro). I place the scanned image in a Picture Box to allow manual cropping. When I place the image in the picture box, it shrinks it down to fit the picture box.

I know the size of the scanned image, and I know the size of the picture box.

I have to figure out how much percent smaller the picture box is than the scanned image. Then, when dragging my crop box over the image, I have to add (or multiply - I'm not sure) the percentage so that I can manipulate the scanned image (in memory).

For example:
The scanned image is 200 High X 100 Wide.
The Picture Box is 100 High X 50 Wide.
How do I figure out how much percent  smaller the Picture Box is than the scanned image?

Then, lets say I drag the crop box as follows:
picBox.Left = 10
picBox.Top = 20
CropBox.Width = 15
CropBox.Heigh = 25

Once I figure out how much percent smaller the PictureBox is, how do I go back to the scanned image and muliply? (by the percentage) the dimensions of my crop box (as if I am working on the  larger scanned image?

0
Comment
Question by:esmyhs
  • 4
  • 3
8 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 500 total points
ID: 34215660
scanned crop box width = cropbox width / pic box width * scanned image width
scanned crop box height = cropbox height / pic box height * scanned image height
0
 
LVL 84

Expert Comment

by:ozo
ID: 34215677
Do you want how much percent smaller for the area or for the linear dimensions?
Does 100% mean no change, or does 0% mean no chang
Can you change the ratio ot width to height?
0
 

Author Comment

by:esmyhs
ID: 34215685
hosneylk:

How would I be able to offset the Top and the Left?

ozo:

I'm not understanding your question. I need to drag the crop box on the visible image, which is proportionality smaller than the actual image in memory. I need to figure out how much smaller the image in the picture box is, and then apply the crop to the image in memory, based on those proportions.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 10

Expert Comment

by:hosneylk
ID: 34215692
scanned crop box top = cropbox top * scanned image height / pic box height
scanned crop box left = cropbox left * scanned image width / pic box width
0
 

Author Comment

by:esmyhs
ID: 34215704
hosneylk:

Top and Height work perfect.

Width and Left are a little off. The image ends up being too narrow, and starting a little too far over to the right...

Any idea why this would happen?
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34215713
try using picturebox.ClientRectangle.Left and Height
0
 

Author Comment

by:esmyhs
ID: 34215737
Truth is that the top and height are off by a little as well. I will attribute it to something in the settings on how I am making the crop box. I should be able to find that problem on my own. If not, I'll open a new question.

Your code works perfect! Thanks a lot!
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34215739
glad to help :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

829 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