Solved

Figure Out Percentages

Posted on 2010-11-25
8
314 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extracting last characters in a substring 5 28
VB.Net Report Printing Issue 3 35
RLDC Reporting in Visual studio 11 16
vb.net class 3 17
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
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…
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…

803 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