Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Figure Out Percentages

Posted on 2010-11-25
8
Medium Priority
?
322 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
[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
  • 4
  • 3
8 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 2000 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

647 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