Monitor DPI for Windows and Mac?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 9960
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Monitor DPI for Windows and Mac?
LC has a way to obtain DPI (pixel density) on mobile, but I don't believe there's anything in the engine to get that info for desktop platforms. I have a case where on-screen display needs to be of a specific real-world size in inches. I can dig up the AppleScript/Powershell combos needed for stuff like that, but before I spend the time it seemed worth asking:
Anyone here seen a Builder script or other LC extension to obtain DPI for desktop monitors?
Anyone here seen a Builder script or other LC extension to obtain DPI for desktop monitors?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Monitor DPI for Windows and Mac?
Richard.
You mean the "mobilePixelDensity()"?
Can't you use the screen/card dimensions to determine the number of X and Y pixels on each axis? And if you have that, doesn't that give you the "desktop pixel density"?
Craig
You mean the "mobilePixelDensity()"?
Can't you use the screen/card dimensions to determine the number of X and Y pixels on each axis? And if you have that, doesn't that give you the "desktop pixel density"?
Craig
Re: Monitor DPI for Windows and Mac?
Ah, I see. You do not want to have to rely on using a caliper to measure the actual size of either the screen or the card window dimensions.
Aha.
Craig
Aha.
Craig
Re: Monitor DPI for Windows and Mac?
Is pixelScale, systemPixelScale, screenPixelScale or screenPixelScales helpful for this?FourthWorld wrote: ↑Wed Apr 03, 2024 10:20 pmLC has a way to obtain DPI (pixel density) on mobile, but I don't believe there's anything in the engine to get that info for desktop platforms. I have a case where on-screen display needs to be of a specific real-world size in inches. I can dig up the AppleScript/Powershell combos needed for stuff like that, but before I spend the time it seemed worth asking:
Anyone here seen a Builder script or other LC extension to obtain DPI for desktop monitors?
Seems like it should be? For multiple monitors the last one seems most appropriate?
-
- VIP Livecode Opensource Backer
- Posts: 9960
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Monitor DPI for Windows and Mac?
Thanks, but those don't return DPI, just multipliers for pixel doubling on high-res displays.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Monitor DPI for Windows and Mac?
According to https://superuser.com/questions/1085734 ... top-screen:
i guess you need a way to get the diagonal dimensions of the screen and know the pixel doubling.
Not sure if that helps?
Code: Select all
PPI = sqrt((pixels_horizontal^2 + pixels_vertical^2) / inches_diagonal)
Not sure if that helps?
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac?
Here's something as crude as a crude thing.
-
-
Only any good for a machine with a single monitor.
Code: Select all
on mouseUp
put item 3 of the screenRect into WIDD
put item 4 of the screenRect into HITE
put the pixelScale into sFACTOR
put WIDD && "x" && HITE into fld "f1"
put WIDD * sFACTOR into vWIDD
put HITE * sFACTOR into vHITE
put vWIDD && "x" && vHITE into fld "f2"
end mouseUp
Only any good for a machine with a single monitor.
- Attachments
-
- SCREENER.livecode.zip
- Stack.
- (1.07 KiB) Downloaded 44 times
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac?
Slightly refined (but probably not up to the standard to put in the tank of your HumVee):
Currently at work, where I have no machine connected to more than 1 monitor . . .
But should (. . . don't hold your breath . . .) give you 'guff' for multiple monitors.
Code: Select all
on mouseUp
put empty into fld "f1"
put empty into fld "f2"
put the screenPixelScales into fld "f4"
put the screenRects into fld "f3"
put the number of lines in fld "f3" into nSCREENS
put 1 into SCREAMS
repeat until SCREAMS > nSCREENS
put item 3 of line SCREAMS of fld "f3" into WIDD
put item 4 of line SCREAMS of fld "f3" into HITE
put line SCREAMS of fld "f4" into sFACTOR
put WIDD && "x" && HITE into line SCREAMS of fld "f1"
put WIDD * sFACTOR into vWIDD
put HITE * sFACTOR into vHITE
put vWIDD && "x" && vHITE into line SCREAMS of fld "f2"
add 1 to SCREAMS
end repeat
end mouseUp
But should (. . . don't hold your breath . . .) give you 'guff' for multiple monitors.
- Attachments
-
- SCREENER 2.livecode.zip
- Stack.
- (1.27 KiB) Downloaded 74 times
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac?
Of course my stack(s) doesn't provide the DPI, but it does supply the scale factor, and, for the sake of argument, as I have a 27" Retina display iMac with 2 "bog normal" monitors riding 'side-saddle' (one on each side), I expect my stack will return both the real and the virtual screen resolutions of all those displays.
This:
"In the case of a monitor, you take the number of pixels (dots) in one direction, and divide it by the displayable inches in that direction, to get the DPI (dots per inch)."
Is a 'right fudge' as, for instance, my 2015 iMac is described as a 27 inch display: and having fooled around with a measuring tape that seems to be the DIAGONAL measurement: and I can see NO benefit in doing the fancy calculations (which are not 'that' fancy) to work out the width and the height of the ting: the virtual screen resolution should suffice.
This:
"In the case of a monitor, you take the number of pixels (dots) in one direction, and divide it by the displayable inches in that direction, to get the DPI (dots per inch)."
Is a 'right fudge' as, for instance, my 2015 iMac is described as a 27 inch display: and having fooled around with a measuring tape that seems to be the DIAGONAL measurement: and I can see NO benefit in doing the fancy calculations (which are not 'that' fancy) to work out the width and the height of the ting: the virtual screen resolution should suffice.
-
- VIP Livecode Opensource Backer
- Posts: 9960
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Monitor DPI for Windows and Mac?
The arithmetic is good, but this is for a deployment where we can't rely on users inputing the screen diagonal.stam wrote: ↑Thu Apr 04, 2024 7:23 amAccording to https://superuser.com/questions/1085734 ... top-screen:
i guess you need a way to get the diagonal dimensions of the screen and know the pixel doubling.Code: Select all
PPI = sqrt((pixels_horizontal^2 + pixels_vertical^2) / inches_diagonal)
Not sure if that helps?
There's likely a Powershell script out there for this. I was just hoping someone had made a Builder function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac?
In front of me I have a 23 inch monitor (i.e. 22.9 inches diagonally): I don't know how a computer is going to 'know' that.
HOWEVER:
https://www.infobyip.com/detectdisplaysize.php
https://www.whatismyscreenresolution.or ... itor-size/
As you can see, it has a wide variety of resolutions it can display:
- -
And, as I demonstrated earlier, I can find the current display resolution, and I can find the pixel density, and from that can derive both the real resolution and the virtual resolution.
At home I have a monitor that can also display at a resolution of 1920 x 1080, but it is a 17 inch monitor.
So: those calculations mentioned above are ONLY any use if there is a way to detect the PHYSICAL SIZE of the monitor attached to a computer.
- -
Which really made my underpants revolve at high speed: how the 'fudge' is that done?
C# "freaks" might like this"
Just all those curly-wurly brackets make my toes curl up.
AND that may only work on Windows.
https://theezitguy.wordpress.com/2016/0 ... matically/
- -
That last image might explain part of the reason I was having 'fun' at the dentist, yet again, this morning.
HOWEVER:
https://www.infobyip.com/detectdisplaysize.php
https://www.whatismyscreenresolution.or ... itor-size/
As you can see, it has a wide variety of resolutions it can display:
- -
And, as I demonstrated earlier, I can find the current display resolution, and I can find the pixel density, and from that can derive both the real resolution and the virtual resolution.
At home I have a monitor that can also display at a resolution of 1920 x 1080, but it is a 17 inch monitor.
So: those calculations mentioned above are ONLY any use if there is a way to detect the PHYSICAL SIZE of the monitor attached to a computer.
- -
Which really made my underpants revolve at high speed: how the 'fudge' is that done?
C# "freaks" might like this"
Code: Select all
using System;
using System.Management;
namespace GetScreenSize
{
class Program
{
static void Main(string[] args)
{
//Get monitor data
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\root\wmi", @"SELECT * FROM WmiMonitorBasicDisplayParams");
//Calculate and output size for each monitor
foreach (ManagementObject managementObject in searcher.Get())
{
//Calculate monitor size
double width = (byte)managementObject["MaxHorizontalImageSize"] / 2.54;
double height = (byte)managementObject["MaxVerticalImageSize"] / 2.54;
double diagonal = Math.Sqrt(width * width + height * height);
//Output monitor size
Console.WriteLine("Monitor Size: {0:F1}\"", diagonal);
}
Console.ReadLine();
}
}
}
AND that may only work on Windows.
https://theezitguy.wordpress.com/2016/0 ... matically/
- -
That last image might explain part of the reason I was having 'fun' at the dentist, yet again, this morning.
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac?
https://lessons.livecode.com/m/4069/l/2 ... esolutions
I wonder why checkForScreenSize does not seem to be in the LC Dictionar?
I wonder why checkForScreenSize does not seem to be in the LC Dictionar?
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Monitor DPI for Windows and Mac: Richmond Finds More Problems.
So: at home with a triple-monitored 'thing' and:
- -
And, as you can see, LiveCode is making a right whoreson's out of monitor number 3.
I thought that might be because of the "default" thing:
- -
BUT my stack STILL returns the same info when set differently:
- -
ALL I have "achieved" in this exercise is exposed another problem with screenRects . . .
What this means is that LiveCode seems completely unable to return the dimensions of the third monitor, which is not very useful at all.
- -
And, as you can see, LiveCode is making a right whoreson's out of monitor number 3.
I thought that might be because of the "default" thing:
- -
BUT my stack STILL returns the same info when set differently:
- -
ALL I have "achieved" in this exercise is exposed another problem with screenRects . . .
What this means is that LiveCode seems completely unable to return the dimensions of the third monitor, which is not very useful at all.