开发者

What's the advantage of device-independent pixels?

开发者 https://www.devze.com 2023-01-25 02:29 出处:网络
I\'m learning about WPF. WPF开发者_运维技巧 uses device-independent pixels. But I can\'t really understand them. Why are they better than device-dependent pixels, if most other apps are device-depende

I'm learning about WPF. WPF开发者_运维技巧 uses device-independent pixels. But I can't really understand them. Why are they better than device-dependent pixels, if most other apps are device-dependent and WPF apps aren't? Would they stick out?


The advantage of device independent pixels is that when specifying a UI you can determine the size that UI components will appear on the user's device, regardless of the user's screen resolution. Unfortunately, it's not quite as simple as that, as it requires the user to have various settings set 'correctly', and it can be overridden by a user who wants to change the resolution of their device (e.g. a partially sighted user who wants to run at a low resolution to make text easier to read).

In addition to the other link posted, you can also check out this one:

Is WPF Really Resolution Independent?

Note that you can turn on snapping a control to device pixels with the SnapsToDevicePixels set to true to avoid the blurriness that occurs when a horizontal/vertical line is drawn on the boundary between two device pixels.


Before understanding device independent unit, it is required to understand what DPI is. DPI is dots per inch, that means there would be certain number (96 usually) of pixels in an inch . But what is important to understand is in Win32 environment this inch is not fixed in size as a physical inch. So when the number of dots increases / decreases by changing the resolution there would more / less number of dots in an inch as a result the "inch" size increases or decreases. However in case of WPF the inch size is as good as a physical inch as a result every time the DPI changes the system adjusts it self accordingly.


It's about UI and font scaling depending on the system's DPI setting:

Not all applications are DPI-aware: some use hardware pixels as the primary unit of measurement; changing the system DPI has no effect on these applications. Many other applications use DPI-aware units to describe font sizes, but use pixels to describe everything else. Making the DPI too small or too large can cause layout problems for these applications, because the applications' text scales with the system's DPI setting, but the applications' UI does not. This problem has been eliminated for applications developed using WPF.

WPF supports automatic scaling by using the device independent pixel as its primary unit of measurement, instead of hardware pixels; graphics and text scale properly without any extra work from the application developer.

This is taken from the link Kishore provided. (http://msdn.microsoft.com/en-us/library/ms748373.aspx)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号