Link to home
Start Free TrialLog in
Avatar of esmyhs
esmyhs

asked on

Figure Out Percentages

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?

ASKER CERTIFIED SOLUTION
Avatar of hosneylk
hosneylk
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
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?
Avatar of esmyhs
esmyhs

ASKER

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.
scanned crop box top = cropbox top * scanned image height / pic box height
scanned crop box left = cropbox left * scanned image width / pic box width
Avatar of esmyhs

ASKER

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?
try using picturebox.ClientRectangle.Left and Height
Avatar of esmyhs

ASKER

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!
glad to help :)