pixel size and "Points"

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.

the size of the points is dependant on the physical hardware of your device… for example an iPhoneX is 458 points per inch

so a canvas the is 100 x 100 will be one size (in inches) on one device and maybe another on a different one.

For printing… a point and a pixel are the same, as they are on any NON-RETINA/HDPI device. (@1x)

On a Retina display a point is 2x2 pixels (@2x)… on an iPhone6/7/8 Plus they are 3x3 pixels (@3x)

but most of Xojo controls measure in POINTS (unless you mess with g.scaleX)

on a 72 dpi printer, but wo have nowadays a 72dpi printer ?

We have - since the early 90s - greyscale (and colors) / 600 and far more dpi printers (I do not even know the actual printers dpi).

We still have a problem in the last 30/40 years between screen and printer dpi (pixels and points). I do not know why.


Indeed, for printing, dots (aka pixels) can be considerably smaller than 1/72nd an inch. Most recent printers are at the minimum 600 dots per an inch.

You have a canvas that is 400 x 600

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
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
now you just drawpicture the image to the whole canvas size in the paint event

[quote=443188:@Jeff Tullin]canvas.width = cwid * scaleby
canvas.height = chei * scaleby[/quote]
Shouldn’t that be

canvas.width = image.width * scaleby
canvas.height = image.height * scaleby

No excuses. I’m off to bed. :slight_smile: