473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.drawst ring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromIm age(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 2112
Do a Google search for Graphics.Measur eString and/or
Graphics.Measur eCharacterRange s. In my experience, if you want a precise
answer, this is a rather complicated area.

Good Luck, Bob

"Massimilia no" <xa****@gmail.c omwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawst ring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromIm age(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
"Massimilia no" <xa****@gmail.c omwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
How I can retreive a dimension in pixel of a character draw
with graphics.drawst ring(...). For example:
imgFont = New Bitmap(48, 48) ' for now dimension is fixed
g = Graphics.FromIm age(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


"Massimilia no" <xa****@gmail.c omschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.drawst ring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromIm age(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


"Massimilia no" <xa****@gmail.c omschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Hi all.
How I can retreive a dimension in pixel of a character draw with
graphics.draws tring(...).

For example:

imgFont = New Bitmap(48, 48) ' for now the dimension is fixed
g = Graphics.FromIm age(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
"Massimilia no" <xa****@gmail.c omwrote in message
news:eI******** *****@TK2MSFTNG P06.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**@WhiskyAnd Coke.comwrote in message
news:uC******** ******@TK2MSFTN GP04.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**@WhiskyAnd Coke.comwrote in message
news:uC******** ******@TK2MSFTN GP04.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
"Massimilia no" <xa****@gmail.c omwrote in message
news:OR******** *****@TK2MSFTNG P03.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
1697
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
13826
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... But how do I know?? Are there any documents on this? any help would be appreciated.. Regards,
12
6744
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"> <span>Abc</span> <span style="background: white; color: black; line-height: 3">Abc</span> <span>Abc</span> </div>
6
5725
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). example: <table... border=0> <tr>
3
8839
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 adjust according to dynamic screen size, and I have been able to adjust the width to a percentage value which works fine. But if I try do the same with the height it shows some very strange results squashing the field to display about 3 lines.
1
6492
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 height to about 150%. I tried using CSS, now I am trying tables. Can someone show me where I am mixing things up? Thanks. --Master Sheet <%@ Master Language="C#" AutoEventWireup="true" CodeFile="master.master.cs" Inherits="pts" %>
3
4428
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%; min-height:100%; } body{ vertical-align:middle;
1
3367
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 browser the height of the layer increased and it shown longer than the regular height which makes troubles with the footer of the website. This is the CSS of the layer: .demo {position:absolute ; top:710px; left:380px; z-index:99; ...
1
5173
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 FF, IE6 and IE7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Employee Listing </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords"...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.