Pixel size of text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bajajv
    New Member
    • Jun 2007
    • 152

    Pixel size of text

    Hi,
    How to get the pixel size of any string? I want to get the length it is taking in terms of pixels.

    Thanks.
  • arnaudk
    Contributor
    • Sep 2007
    • 425

    #2
    What do you mean by a "pixel"?

    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. :-)

    Comment

    • bajajv
      New Member
      • Jun 2007
      • 152

      #3
      I mean that the lowest straight line joining the two ends of that string will contain how many pixels. I want to calculate that.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Which font do you want to use?
        What is the point size?
        What is the glyph layout?
        What about kerning?
        etc...

        Comment

        • SpecialKay
          New Member
          • Mar 2008
          • 109

          #5
          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.

          Comment

          • arnaudk
            Contributor
            • Sep 2007
            • 425

            #6
            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.

            Comment

            • bajajv
              New Member
              • Jun 2007
              • 152

              #7
              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.

              Comment

              • questionit
                Contributor
                • Feb 2007
                • 553

                #8
                Originally posted by bajajv
                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 ?

                Qi

                Comment

                • bajajv
                  New Member
                  • Jun 2007
                  • 152

                  #9
                  Originally posted by questionit
                  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.

                  Comment

                  • Sick0Fant
                    New Member
                    • Feb 2008
                    • 121

                    #10
                    Originally posted by bajajv
                    Yaa, thats right. I am making an application which includes some sort of animation. For that I was thinking to make such a function.
                    What graphics library are you using? This is something you should be able to look up in documentation, right?

                    Comment

                    • oler1s
                      Recognized Expert Contributor
                      • Aug 2007
                      • 671

                      #11
                      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.

                      Comment

                      • bajajv
                        New Member
                        • Jun 2007
                        • 152

                        #12
                        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

                        Working...