Jump to content

How to convert a pixel font size to scale?


LPX

Recommended Posts

17 hours ago, LPX said:

the dxDrawText function has a parameter for the font size as a scale, but I only have the pixel size, how can I convert the pixel to scale. ex: 12px -> ?

To convert pixel size to scale, you can use the following formula:

scale = pixel size / 12

In this formula, "pixel size" represents the font size in pixels that you want to convert, and "12" represents 12 pixels which correspond to the default dpi/ppi value.

For example, a font size of 12 pixels would have a scale value of 1:

scale = 12 / 12 = 1

A font size of 15 pixels would have a scale value calculated as follows:

scale = 15 / 12 = 1.25

The actual conversion can vary depending on the dpi/ppi value used, but a default value of 96 is typically assumed.

 

-- define the default dpi/ppi value
local dpi = 96

-- enter the pixel size you want to convert
local pixelSize = 12

-- use the formula to convert pixel size to scale value
local scale = pixelSize / (dpi / 12)

-- print the scale value
print("Scale value: ", scale)

 

Edited by Shady1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...