Read screen scaling and screen resolution

Hi,

We are having problem in reading screen resolution and scaling factor from smart client. Resolution of 3200x1800 with 150% scaling is actually screen resolution of 2133x1200.

Following code in standalone app returns width=2133 (in single screen setup)

foreach (Screen screen in Screen.AllScreens)

       {

           MessageBox.Show(screen.Bounds.Width.ToString());

       }

The same code from Smart Client WorkSpaceViewItemUserControl returns width=3200 and this is not correct. Function is called inside Init() procedure.

How can we read screen current width and height

?

For better understanding, can you please tell us what you intend to use it?

Because we did some changes in this area and concluded that it might be very difficult to make it work perfectly.

On the other hand, the scaling values are actually quite easily accessible in a WPF application, so you could just extract those values and divide the results if needed.

Another thing is that, this could be related to the fact that the Smart Client is not “per monitor DPI aware”.

This basically means that it is the scaling you have applied on your primary monitor which takes effect; not the scaling on the monitor which the SC is currently displayed on.

Hi,

Unfortunately, we are not using wpf.

Our purpose is to use video stream from dome camera to control PTZ camera. For example, parking lot has 5 dome and one PTZ camera, and in camera 2 person is detected. System directs PTZ camera in that direction and applies calculated level of zoom for closeup recording.

Math behind this scenario is following: video analytics over camera 2 video stream will output “person detected on 200x200 pixels”.

If camera 2 is embedded in Smart Client 2x2 view on 1920*1080 screen, we can say that it’s video is displayed on 960x540 pixels. This is not true, but error here is not relevant to this topic. This means that camera 2 field of view is mapped on a 960x540 resolution. When a person is detected in location 200x200 this location is relevant to 960x540 resolution and with this data we are starting our math and rest if working fine.

But, if scaling 125% is applied, screen resolution is changed to 1536x864 pixels. This means that video from camera 2 is now displayed on 768x432 pixels. Camera 2 field of view is displayed on 768x432 pixels resolution. Here is the problem, Smart Client is still saying that resolution is 1920x1080 when 125% scaling is applied, and we can not get the scaling variable from Smart Client.

We have found a solution and that is to ask the user to type in the scaling, but we are not happy about it.

Why the scaling is important?

We are using video camera as visual sensor. Video camera has a field of view that is mapped on some sensor and that is a screen. Person in camera field of view is detected as a person on screen. Its location in camera field of view corresponds with it’s location on a screen. When resolution is changed, field of view to screen resolution is changed also. Changing the resolution by changing the scaling is not a problem, but problem is us not knowing about it. Our math has to be adjusted accordingly.

I think that knowing scaling parameter is important to developer, not just because we are using it, but for a future purpose. Here is one example, Axis Object Analytics sends metadata info that person is detected on 200x200 pixels in 1920x1080 video resolution. If the same video is displayed in Smart Client in single camera view and screen has scaling of 125%, placing a bounding box in location 200x200 is wrong. Bounding box must be placed at location 160x160. Because Smart Client screen resolution is not 1920x1080 it is 1536x864. So, when displaying results from EDGE analytics screen scaling must be taken into account.

Best Regards,

Hrvoje

This is a bit strange, we are not sure why you don’t think you can get the scaling from code…

Please see below sample code –

public static (double, double) GetDpiScaling()
{
    return (Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth, Screen.PrimaryScreen.Bounds.Height / SystemParameters.PrimaryScreenHeight);
}

The above code returns the scaling values (xScaling, yScaling).

You mention that you are a WinForms plugin (this is what we presume), so you will need to add a reference to “PresentationFramework” in your project to have access to the SystemParameters class.

Thanks Kito,

it is working now. It was a problem with reference that we overlooked.

Hrvoje