问题
I need to convert between Drawing.Font.Size
(float, ?) and WPF FontSize
(double, WPF pixels).
Finally, I decided to store in the database the fontSize in inch...
How can I convert the GDI FontSize to inch and the WPF FontSize to inch?
sizeInInch = wpfFontSize / 96
sizeInInch = gdiFontSize / ?
Can I use something DPI independent? Maybe System.Windows.FontSizeConverter
?
I need to convert to something, that will allow me to switch multiple time between WPF and GDI without changing the "real value".
Each division and following multiplication will accumulate errors...
FontSizeConverter does a ConvertTo, but I don't understand to use it: say
myUniversalFontSize = (double)(myFontSizeConverter.ConvertFrom(
gdiFont.SizeInPoints.ToString() + "pt"))
will transform my gdiFont size in ...? WPF Pixels?
How now should I convert back that value to GDI?
gdiFont.SizeInPoints = myUniversalFontSize / 96 * 72???
Can I use in the second example the myFontSizeConverter
too?
回答1:
See documentation http://msdn.microsoft.com/en-us/library/system.windows.controls.control.fontsize.aspx
"in is inches; 1in==96px"
Use a LengthConverter for conversion. http://msdn.microsoft.com/en-us/library/system.windows.lengthconverter.aspx
回答2:
Don't know much about the WPF stuff, but if there is a method to convert from pixels to points, you can use the scale of 1 inch = 72 points.
来源:https://stackoverflow.com/questions/9840810/convert-the-font-size-in-inch