At least my problem is a little better defined now. I am inputting an image size in inches ( such as 11" by 14" ) in 2 text fields. I have a canvas defined on the screen that simply fits the available space. It starts out as 400 by 600 Pixels (or Points). Since the aspect of the image dimensions
won’t always be the same as the canvas aspect ratio, I want to adjust the canvas to match the aspect ration of the image but keep it an appropriate size on the screen. There does not have to be a direct relation to the inches of the image to the pixels of the canvas - but the aspect ration of the canvas needs to be set to the aspect of the image to keep the proportions correct. Isn’t the actual size of the pixels dependant on the resolution of the screen? The canvas documentation says that height and width are expressed in points. How do points relate to pixels here.
For background, this is a Mat cutting calculator. There are actually 2 canvases - one that represents the image size and another one that represents the over mat with added margins and etcetera.
You have an image that is by
You want to display the image inside the 400 x 600 area so that it fits, and stays the same shape.
Consider how much you need to shrink the width by to fit inside 400
400 / image width = (maybe) 0.65
Consider how much you need to shrink the height to fit inside
600 / imageheight = (maybe) 0.34
In this example, 0.34 is 34% of the original height, versus 65% of the original width.
So height is the deciding factor
[code]dim scaleby as double
dim cwid as double - canvas.width
dim chei as double = canvas.height
if canvas.width/image.width < canvas.height / image.height then
scaleby = canvas.width/image.width
else
scaleby = canvas.height / image.height
end if
//Now, you draw the image inside your canvas, or change the canvas to the new size, and draw the picture into it.
//Lets change the canvas:
canvas.width = cwid * scaleby
canvas.height = chei * scaleby
[/code]
now you just drawpicture the image to the whole canvas size in the paint event