A pixel is graphics element. A string is an array of characters. What do these have in common? It's like asking how much a pound of butter weighs in degrees Fahrenheit. :-)
you could use a ruler... joking.
But i must say, that i dont think you are going to be able to do this... i mean, if you know what the string is going to be before hand. then yes. But different characters take up different amounts of pixels. I suppose you could somehow make a table, in the table have ever possible character with a matching "pixel" length. then have a loop through the string and add up all the pixels...
just my input... sorry if its not helpful.
The question lacks a lot of detail. It's like if I were to ask "How do I work out the maximum speed of any car?" (Sorry about my metaphors :-) You can just try it, which is like using a ruler. It is possible to work out as well but depends on very many factors. volume of cylinders, frictional losses, fuel, weight, aerodynamic drag, gearbox, etc etc. like w4cats mentions.
Now if you're restricting yourself to a DOS console with a certain resolution it's more feasible since it looks like each character occupies the same width and there is constant kerning.
Well, I was just thinking to make a default function, which takes all the details from the system itself, and then returns the number of pixels. But anyway, if it requires so many things, then better I leave it for now.. :))
Thanks for all your comments.
Well, I was just thinking to make a default function, which takes all the details from the system itself, and then returns the number of pixels. But anyway, if it requires so many things, then better I leave it for now.. :))
Thanks for all your comments.
I think the questioneer has made his question very clear.
Regardless of what Compiler, editor, screen, Pc he uses, the text that appears on the screen, he wants to get the size/number of pixels that the text or each letter in the text has consumed on the screen.. is this right ?
I think the questioneer has made his question very clear.
Regardless of what Compiler, editor, screen, Pc he uses, the text that appears on the screen, he wants to get the size/number of pixels that the text or each letter in the text has consumed on the screen.. is this right ?
Qi
Yaa, thats right. I am making an application which includes some sort of animation. For that I was thinking to make such a function.
I think the questioneer has made his question very clear.
Regardless of what Compiler, editor, screen, Pc he uses, the text that appears on the screen, he wants to get the size/number of pixels that the text or each letter in the text has consumed on the screen.. is this right ?
The question is clear. We are saying that the answer to it is also clear: there is no possible answer to it.
A string is not a graphic object. The idea of distance in pixels only applies to graphics. Therefore, you would have to somehow realize this string graphically. Which of course depends entirely on the text rendering system you use, the graphics system you use, and the parameters for typesetting the string.
It's not that it's impossible to get the pixel length of a string. You just missed out everything in between.
Actually, we don't have much details about the library, except some of its APIs. Thats why, I was trying for some function myself. But yes, I have missed out everything in between, so will need some more time to work things out :))
Comment