Solved

Figure Out Percentages

Posted on 2010-11-25
8
311 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now