Determine Pixel Length of Text String
Show older comments
Hi Guys,
I was wondering if there was a way to determine the pixel length for a given text? I know there is a way to do this once a text object has been created on a graph etc., but I am particular looking for a way to do this without having to even create an object. That way I would know what the bounding box size would have to be.
Thanks
2 Comments
Matt Kindig
on 1 Jul 2013
This question doesn't make sense to me. Fonts are usually defined in terms of Bezier curves, which by definition are vectorized and thus can be rendered at any scale. So the pixel representation of the text string isn't defined until it is a rendered, and the number of pixels will of course depend on the font size. I'm not exactly sure what you are asking to do.
Nitin
on 1 Jul 2013
an example of what you are trying to achieve would probably make it easier..
Accepted Answer
More Answers (1)
Jasper van Casteren
on 10 May 2017
3 votes
The answers seem to miss the point. Often, to make a nice app dialog, you want to set the width of text boxes to the largest width. So you would have to find the size of a text in pixels if you cannot design your whole dialog in character units (which is often the case). So, the question is not whether you need to render before you know it, but whether there is a "quite" renderer that does the rendering but only returns the size of the box, without actually displaying something.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!