Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics.MeasureString() returns size in Point or Pixel?

I use Graphics.MeasureString to calculate size of a text. EG: 10 pixel = 7.5 Point.

My question: Is the size calculated from Graphics.MeasureString point value or pixel value?

like image 975
Amal Avatar asked Oct 18 '25 14:10

Amal


2 Answers

From the MSDN page:

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter.

The PageUnit is of type GraphicsUnit which is an enum with the following values

Member name Description
Display Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers.
Document Specifies the document unit (1/300 inch) as the unit of measure.
Inch Specifies the inch as the unit of measure.
Millimeter Specifies the millimeter as the unit of measure.
Pixel Specifies a device pixel as the unit of measure.
Point Specifies a printer's point (1/72 inch) as the unit of measure.
World Specifies the world coordinate system unit as the unit of measure.

Apologies for the terrible formatting!

like image 102
Matt Hogan-Jones Avatar answered Oct 21 '25 02:10

Matt Hogan-Jones


You can use Graphics.PageUnit in order to set the return type of measurement. So it can be either Pixel or Point, it is your choice

like image 42
liamguy165 Avatar answered Oct 21 '25 02:10

liamguy165



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!