Question

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...

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top