Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get screen DPI (linux,mac) programatically?

I need to know active screen DPI on Linux and Mac OS. I think on linux xlib might be useful, but I can't find a way how to get currect DPI. I want this information to get real screen size in inches.

Thanks in advance!

like image 995
k3a Avatar asked Apr 12 '10 10:04

k3a


People also ask

How do I change DPI in Ubuntu?

The default dpi in Ubuntu is set-up to 96. To increase it, you will have to go to properties of the desktop. This you can do by right clicking your mouse or using the properties button of your keyboard. A window will appear and you will a “Font” tab on the upper side of this window.


2 Answers

On a mac, use CGDisplayScreenSize to get the screen size in millimeters.

like image 63
uli Avatar answered Oct 06 '22 16:10

uli


In X on Linux, call XOpenDisplay() to get the Display, then use DisplayWidthMM() and DisplayHeightMM() together with DisplayWidth() and DisplayHeight() to compute the DPI.

On the Mac, there's almost certainly a more native API to use than X. Mac OS X does not run X Window by default, it has a native windowing environment.

like image 34
unwind Avatar answered Oct 06 '22 15:10

unwind