473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Hot to get Widht an Height of a charatter in a specified font

Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawstring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromImage(imgFont)
g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)

How I can give a exatly dimension to the bitmap for contain a single
character withouth spacing?
Thanks
Modena Massimiliano
Nov 4 '08 #1
8 2095
Do a Google search for Graphics.MeasureString and/or
Graphics.MeasureCharacterRanges. In my experience, if you want a precise
answer, this is a rather complicated area.

Good Luck, Bob

"Massimiliano" <xa****@gmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawstring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromImage(imgFont)
g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)

How I can give a exatly dimension to the bitmap for contain a single
character withouth spacing?
Thanks
Modena Massimiliano

Nov 4 '08 #2
"Massimiliano" <xa****@gmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
How I can retreive a dimension in pixel of a character draw
with graphics.drawstring(...). For example:
imgFont = New Bitmap(48, 48) ' for now dimension is fixed
g = Graphics.FromImage(imgFont)
g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)
How I can give a exatly dimension to the bitmap for contain
a single character withouth spacing?
Not quite sure what you mean by "without spacing"? Do you mean you want just
the area actually occupied by the character glyph itself excluding any
surrounding white space within the character cell? If so then you'll
probably need to use the GetGlyphOutline GDI function using GGO_METRICS as
the uFormat parameter, which will return a GlyphMetrics structure for you
containing, amongst other things, gmBlackBoxX, gmBlackBoxY and
gmptGlyphOrigin which tell you the size and position within the character
cell of the smallest rectangle that completely encloses the glyph.
Incidentally these things, as with most things concerning fonts, are device
dependent and the values returned even for the same font and character will
often be different on different displays and printers, depending mostly on
their dpi resolution. By the way, there may actually be a vb.net native
method to get this stuff for you, but I wouldn't know about because I
actually use only VB6 and I just happened to be nosing around in here :-)

Mike
Nov 4 '08 #3

Did you already tried the measure string method

http://msdn.microsoft.com/en-us/libr...urestring.aspx

HTH

Michel


"Massimiliano" <xa****@gmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawstring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromImage(imgFont)
g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)

How I can give a exatly dimension to the bitmap for contain a single
character withouth spacing?
Thanks
Modena Massimiliano

Nov 4 '08 #4
Michel Posseth [MCP] wrote:
Did you already tried the measure string method

http://msdn.microsoft.com/en-us/libr...urestring.aspx

HTH

Michel


"Massimiliano" <xa****@gmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawstring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromImage(imgFont)
g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)

How I can give a exatly dimension to the bitmap for contain a single
character withouth spacing?
Thanks
Modena Massimiliano

the measureString function is perfect! Thanks a lot!
Massimiliano
Nov 10 '08 #5
"Massimiliano" <xa****@gmail.comwrote in message
news:eI*************@TK2MSFTNGP06.phx.gbl...
>Michel Posseth [MCP] wrote:
Did you already tried the measure string method
http://msdn.microsoft.com/en-us/libr...urestring.aspx

the measureString function is perfect! Thanks a lot!
Massimiliano
As a matter of interest, does that return the width of the actual drawn
glyph or the width of the character cell containing the glyph or perhaps the
width of the character cell plus a little extra for any possible overhang? I
haven't got vb.net installed and so I can't try it myself, but I'm
interested nonetheless in the way it natively handles fonts. In your
original post you asked how to find the width of a single character "without
spacing" and I asked whether you meant the width of the glyph without its
surrounding character cell white space, but you did not answer. For example,
if you draw in a Times New Roman 100 point font in Italic what does the
measurestring function return (in pixels) for the character "f" and for the
character "." (the decimal point or full stop or period or whatever you call
it)?

Mike
Nov 10 '08 #6
"Mike Williams" <Mi**@WhiskyAndCoke.comwrote in message
news:uC**************@TK2MSFTNGP04.phx.gbl...

.. . . further to my recent post asking what value the measurestring function
returns in pixels for the 100 point Times New Roman Italic characters "f"
and "." I naturally meant when those characters are drawn to a standard
display (which usually runs at 96 pixels per logical inch) but if you are
using a display running at some other dpi resolution (perhaps 120 dpi or
something else) then I'd need to know the curent dpi resolution of your
machine as well as the reported pixel font widths. Hope you don't mind
checking this for me.

Mike

Nov 10 '08 #7
Mike Williams wrote:
"Mike Williams" <Mi**@WhiskyAndCoke.comwrote in message
news:uC**************@TK2MSFTNGP04.phx.gbl...

. . . further to my recent post asking what value the measurestring
function returns in pixels for the 100 point Times New Roman Italic
characters "f" and "." I naturally meant when those characters are drawn
to a standard display (which usually runs at 96 pixels per logical inch)
but if you are using a display running at some other dpi resolution
(perhaps 120 dpi or something else) then I'd need to know the curent dpi
resolution of your machine as well as the reported pixel font widths.
Hope you don't mind checking this for me.

Mike
I don't say how change the dpi of my screen.
the 'f' char is 82*164 pixel @ 96dpi. the '.' is 79*164pixel.
The bitmap generated it's for an embebbed sistem that draw a bitmap for
each char. I don't need any vectorial sistem.
Nov 10 '08 #8
"Massimiliano" <xa****@gmail.comwrote in message
news:OR*************@TK2MSFTNGP03.phx.gbl...
the 'f' char is 82*164 pixel @ 96dpi. the '.' is 79*164pixel
[in each case using 100 point Times New Roman Italic]
Right. Thanks a lot. It looks as though the MeasureString method is
returning the height and width of the rectangular character cell including
the white space, otherwise the width of the italic "." character would be
very much less than the width of the italic "f" character. Also, because in
both cases the height is about right but the width is about twice what I
would have expected it looks as though the MeasureString method is adding
some extra pixels to account for the fact that some characters have a
considerable underhang and overhang and that it is adding those pixels
whether or not the actual character at either the beginning or the end of
the string you are measuring actually does have either underhang or
overhang. Also, since MeasureString is apparently suitable for your needs, I
think I can safely assume that your answer to my original question when I
asked whether by "without spacing" you meant that you wanted to measure just
the size of the glyph itself would be "No".
The bitmap generated it's for an embebbed sistem that draw a
bitmap for each char. I don't need any vectorial sistem.
When I said that you might like to use the GDI GetGlyphOutline function I
didn't actually mean that you should use it to obtain the vector graphic
"shape" of the character (although it is of course capable of performing
such a task). I meant that you might like to use it to return the width and
height of the "black box" that exactly encloses the drawn "glyph", which is
another use for the function, because I wasn't sure what you were after when
you said that you wanted the size of a character "without the space". As it
turns out, and something which I didn't know at the time, you are after the
character size purely to create a bitmap of a suitable size for drawing as a
bitmap in an embedded system, in which case the size of the glyph is very
definitely not what you want, and the character cell size is what you
require.

Thank you for the feedback.

Mike

Nov 10 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bennie | last post by:
Hi, I can resize in IE whit window.resizeTo(widht,height) but it don't work for Netscape? Have try location.reload() in Netscape. But this don't work.... Any idear? Bennie,
11
by: Rithish | last post by:
If I have something like, <TABLE><TR><TD STYLE="'Font-Family:Arial'">Arial Text</TD></TR></TABLE> What would be the height of the cell? I believe it would be corresponding to the font used......
12
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5">...
6
by: Bruce | last post by:
Hi - I've been looking all over for this and found everything but the variation I need. I have a one-row HTML table with a page title, as text, with a specified font and size (not style). ...
3
by: Les Juby | last post by:
I am trying to adjust the window/table size of a website (www.worklaw.co.za) which has made use of DIV tags with its settings embedded in an CSS file. The client wants its width and height to...
1
by: Mike Collins | last post by:
I am trying to create some pages and have them take 100% of the window, but I cannot get 100% to work. If I set the height of my div, the page displays a scroll bar and it looks like I set the...
3
by: acunnon | last post by:
I am trying to put together an login page my problem is getting the three items aligned to the middle verticaly without specifing a height to anything on the page. CSS html{ height:100%;...
1
by: mascouta | last post by:
I have a lot of problems with IE browser, one of them is described in this topic. in my website i have div Calculator with background image. it displayed perfectly with Firefox browser however in IE...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.