Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How to get pixels per millimeter for current screen?
How to get pixels per millimeter for current screen? [message #36037] Fri, 20 April 2012 11:47 Go to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
I'm implementing some WYSIWYG functionality and need to calculate
sizes specified in mm to the correct on-screen representation in
pixels.

Where/how do I get the pixel-to-mm ratio?

[edit]
I'm trying:

void checkresolution::Paint(Draw &w)
{
Size szpmm = w.GetPageMMs();
Size szpp = w.GetPagePixels();

double ppmmx = (double)szpp.cx/(double)szpmm.cx;
double ppmmy = (double)szpp.cy/(double)szpmm.cy;
//double dppmm = (ppmmx + ppmmy)/2;

//int ppmm = (int)(dppmm + 0.5);
int ppmm = (int)(ppmmx + 0.5);

int cm3 = (int)(ppmm * 30.0);
int cm7 = (int)(ppmm * 70.0);

w.DrawLine(10,10,cm3,10,3,Black());
w.DrawLine(10,15,cm7,15,3,Black());

}

The value I get is not quite correct, but seems that this is
the best I can hope for? The error occurs with the rounding
from double to int that Draw requires.

[Updated on: Sat, 21 April 2012 08:15]

Report message to a moderator

Re: How to get pixels per millimeter for current screen? [message #36038 is a reply to message #36037] Fri, 20 April 2012 22:01 Go to previous messageGo to next message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi Slashupp,

Screens resolution is generally 72ppp (pixels per inch).As one inch is 25.4 mm we can calculate that 72/25.4 = 2.8 pixels in 1mm.

Hope it could be helpful.

Regards

Biobytes
Re: How to get pixels per millimeter for current screen? [message #36044 is a reply to message #36038] Sat, 21 April 2012 06:49 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
"Screens resolution is generally 72ppp (pixels per inch). As one inch is 25.4 mm we can calculate that 72/25.4 = 2.8 pixels in 1mm."

That can't be right? It does not differentiate between say a 15-inch monitor and a 24-inch one...
Re: How to get pixels per millimeter for current screen? [message #36045 is a reply to message #36044] Sat, 21 April 2012 10:29 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hello,

in the Paint(Draw&w) methode, you can use :

Size sz = w.GetPixelsPerInch();


then convert it from inch to mm.

Omari.


regards
omari.
Re: How to get pixels per millimeter for current screen? [message #36063 is a reply to message #36045] Sun, 22 April 2012 21:48 Go to previous message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi,

If you're using Windows, a call to WinAPI32 is possible using the following code:

HDC screen = GetDC(NULL); 
int hSize=GetDeviceCaps(screen,HORZSIZE); int hRes=GetDeviceCaps

(screen,HORZRES); float PixelsPerMM=(float)hRes/hSize;// pixels per millimeter float 

PixelsPerInch=PixelsPerMM*25.4; //dpi 


GetDeviceCaps is a function that also gives information on printers resolution.

Regards Smile

Biobytes
Previous Topic: Zooming layout in Windows
Next Topic: Storing / Inserting Data per BIT
Goto Forum:
  


Current Time: Fri Mar 29 16:29:36 CET 2024

Total time taken to generate the page: 0.01722 seconds