I have created a new Bitmap object and now want do draw some text to it using GDI+. So I call Graphics.DrawString(...).
The problem is that the size of the string depends on Windows 7's DPI settings. Is there any way to make my text drawing independent of the windows settings?
PS: The DPI settings seem to affect text only. A rect for example stys the same size when changing the DPI...
Dots per inch (DPI) is the physical measurement of the number of individual dots that can be placed in a line within the span of 1 inch. DPI setting controls the size of the text, apps and icons. A lower DPI setting will make them appear smaller and a higher setting will make them appear bigger.
A 12-point font is 16 pixels tall. 12 points = 12/72 logical inch = 1/6 logical inch = 96/6 pixels = 16 pixels. This scaling factor is described as 96 dots per inch (DPI). The term dots derives from printing, where physical dots of ink are put onto paper.
High DPI stands for High Dots Per Inch. It represents the pixel density; the higher the DPI, the higher the density of pixels. On 4K screens, the pixel density can be so high that displaying, as usual, would make all icons and controls extremely small.
Double-click Display icon (can also right-click on desktop and select Properties). Select Settings. Select Advanced. Under the General tab, find the DPI setting.
Just found the solution myself: The key is to create the font with the parameter GraphicsUnit.Pixel. That way drawing strings gets independent from the system's DPI settings.
You are correct in that the DPI affects only drawable items that are measured in device-independent units. Fonts are typically measured in Points, where 1 point = 1/72 of an inch. Therefore a 10pt font will be the same size in INCHES on each and every screen resolution and will take up more or less pixels depending on the screen resolution and pixel density.
Everything measured in pixels (such as lines, shapes etc) will not be affected by DPI, but the actual physical size will vary depending on screen resolution and pixel density. Changing your code to measure fonts in pixels will indeed ensure that the text is the same pixel size on all screen DPI settings, but if you were to print to a printer you'll find that the text size will vary depending on printer resolution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With