Hi,
How to get the pixel size of any string? I want to get the length it is taking in terms of pixels.
Thanks.
11 4570
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. :-)
I mean that the lowest straight line joining the two ends of that string will contain how many pixels. I want to calculate that.
Which font do you want to use?
What is the point size?
What is the glyph layout?
What about kerning?
etc...
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 ?
Qi
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.
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?
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 :))
Sign in to post your reply or Sign up for a free account.
Similar topics
by: R0bert Neville |
last post by:
I am having major issues in IE. This web development exercise involves
learning why certain hacks work and others don't. My web page renders
ok in Firefox.
The main problem in my web page...
|
by: grogerteal |
last post by:
Hello,
I am pretty new to programming and would like someone to help me get
started on the program that I need to make.
I hope it is not hard to do, but what I would like is a simple app that...
|
by: victor |
last post by:
hello,
I have several arrays containing (image-) pixel data; I want to
display it onto a PictureBox.
What is the best Graphics method for it?
(MSDN examples talks only about loading it from...
|
by: Sangeeta |
last post by:
Hi,
I have a datagrid where columns are of some fixed pixel size. If any
column text increases the width of column, the plan is to truncate it
till its pixel width becomes less than the coloumn...
|
by: Kirk Graves |
last post by:
I have an html table that I am filling with data from the database. when I
put the text in the table, I only display the number of characters that will
fit based on the size of the cell.
I know...
|
by: steven |
last post by:
Hello,
I'm having some difficulties with labels. Suppose I have 2 labels, with
a random text in the default font (Microsoft Sans Serif). I want to
place them next to each other, with minimal...
|
by: Dave (DreamIsle) |
last post by:
Hello. I'm working on a layout that I need to be pixel specific. How
can I get the font to stay precisely the height I need? Specifying
line-height or font-size in px doesn't yield the results I...
|
by: Piotrekk |
last post by:
Hi
I was wandering if is this possible to resize window in steps
different than 1 px.
Thanks
PK
|
by: teo |
last post by:
Hallo,
I'd like to retrieve the pixel length of a string.
------------------------
I decided to use MeasureString,
but I have a problem with the graphic "instance" of it.
I'm in a Sub
and
|
by: ofiras |
last post by:
Hi,
I made a "Paint" program, but I couldn't find a method to paint 1
pixel using graphic state ("Graphics g =
Graphics.FromHwnd(this.Handle);")
How can I paint 1 pixel?
I guess I can make a...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |