Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point to pixel conversion

On Mac OS X, I need to convert a point measurement to pixel measurement.

The formula which I know is

pixel   = point * resolution (in terms of dpi) / 72

I have few measurements which I want to convert to pixels. Although reverse cases would also be possible.

How to do this in Cocoa or Quartz? Does it depend on axis? Means would 5 pixels in Y-axis would be same as 5 pixels in X-axis in terms of points? Or is it safe to assume that resolution is same for both X and Y axis?

Please note that I do not want to make any assumption about resolution.

like image 889
doptimusprime Avatar asked Jan 12 '23 00:01

doptimusprime


1 Answers

You probably don't want to convert anything to pixels. OS X now works in points; so for example when you draw a rectangle you are giving its dimensions in points, not pixels.

A OS X Quartz point is related to, but not the same as, a (computer) printing point - the two used to be the same, 72 points = 1". However WYSIWYG has become "some scale of" and 72 points (note not pixels) on screen is not a physical inch as screen pixel densities have increased. However 72 points is still an "abstract" inch.

In OS X you draw in points, the OS takes care of mapping those points to the physical pixels on the screen; which roughly translates to screens up to a certain density being treated as 72ppi (pixels/inch) or 1 pixel/point, and higher density screens being treated as 144ppi or 2 pixel/point - for example these are the ppi assigned to standard and Retina screenshots.

If you really, really need to know what a point translates to in pixels you can find out, but this changes depending on what screen a window is on.

For details of all of this you can start with Points Don’t Correspond to Pixels and then read the rest of the High Resolution Guidelines for OS X that reference is part of. How to find point to backing store mapping, if you really, really need to know, is covered.

HTH

like image 51
CRD Avatar answered Jan 23 '23 00:01

CRD