473,763 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Graphics rendering question

Hi,

I am using the following code to render a text string in a new bitmap
file. The code works, but the text looks, well, crappy, even though I
told it to use ClearType hints. Any idea how to make the text look
nicer?

Thanks
Andy

internal static string RenderDate( DateTime date ) {
Bitmap bitmap;
string result, formattedDate;
Font font;
Graphics canvas;
SizeF textSize;
SolidBrush brush;

result = Path.Combine(
Path.GetTempPat h(),
date.ToString( "ddMMyyyy" )
);
result = Path.ChangeExte nsion( result, ".bmp" );
formattedDate = date.ToString( "d" );

using ( font =
new Font( FontFamily.Gene ricSansSerif, 12,
FontStyle.Regul ar )
) {
using ( bitmap = new Bitmap( 1, 1 ) ) {
using ( canvas = Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
textSize =
canvas.MeasureS tring( formattedDate, font );
}
}

using ( brush = new SolidBrush( Color.Black ) ) {
using ( bitmap = new Bitmap(

Convert.ToInt32 ( System.Math.Cei ling( textSize.Width ) ),

Convert.ToInt32 ( System.Math.Cei ling( textSize.Height ) )
) ) {

using ( canvas =
Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
canvas.DrawStri ng(
formattedDate,
font,
brush,
new PointF( 0, 0 )
);
}

//
bitmap.RotateFl ip( RotateFlipType. Rotate270FlipNo ne );

if ( File.Exists( result ) ) {
File.Delete( result );
}
bitmap.Save( result );
}
}
}

return result;
}

Oct 18 '07 #1
5 4065
Andy,

Well, the standard sans serif font, as far as I know, is not a ClearType
font. Have you tried looking at any of the other TextRenderingHi nt values?
like AntiAlias or AntiAliasGridFi t?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Andy" <an***@med-associates.comw rote in message
news:11******** **************@ i13g2000prf.goo glegroups.com.. .
Hi,

I am using the following code to render a text string in a new bitmap
file. The code works, but the text looks, well, crappy, even though I
told it to use ClearType hints. Any idea how to make the text look
nicer?

Thanks
Andy

internal static string RenderDate( DateTime date ) {
Bitmap bitmap;
string result, formattedDate;
Font font;
Graphics canvas;
SizeF textSize;
SolidBrush brush;

result = Path.Combine(
Path.GetTempPat h(),
date.ToString( "ddMMyyyy" )
);
result = Path.ChangeExte nsion( result, ".bmp" );
formattedDate = date.ToString( "d" );

using ( font =
new Font( FontFamily.Gene ricSansSerif, 12,
FontStyle.Regul ar )
) {
using ( bitmap = new Bitmap( 1, 1 ) ) {
using ( canvas = Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
textSize =
canvas.MeasureS tring( formattedDate, font );
}
}

using ( brush = new SolidBrush( Color.Black ) ) {
using ( bitmap = new Bitmap(

Convert.ToInt32 ( System.Math.Cei ling( textSize.Width ) ),

Convert.ToInt32 ( System.Math.Cei ling( textSize.Height ) )
) ) {

using ( canvas =
Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
canvas.DrawStri ng(
formattedDate,
font,
brush,
new PointF( 0, 0 )
);
}

//
bitmap.RotateFl ip( RotateFlipType. Rotate270FlipNo ne );

if ( File.Exists( result ) ) {
File.Delete( result );
}
bitmap.Save( result );
}
}
}

return result;
}

Oct 18 '07 #2
Andy,

Well, the standard sans serif font, as far as I know, is not a ClearType
font. Have you tried looking at any of the other TextRenderingHi nt values
like AntiAlias or AntiAliasGridFi t?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Andy" <an***@med-associates.comw rote in message
news:11******** **************@ i13g2000prf.goo glegroups.com.. .
Hi,

I am using the following code to render a text string in a new bitmap
file. The code works, but the text looks, well, crappy, even though I
told it to use ClearType hints. Any idea how to make the text look
nicer?

Thanks
Andy

internal static string RenderDate( DateTime date ) {
Bitmap bitmap;
string result, formattedDate;
Font font;
Graphics canvas;
SizeF textSize;
SolidBrush brush;

result = Path.Combine(
Path.GetTempPat h(),
date.ToString( "ddMMyyyy" )
);
result = Path.ChangeExte nsion( result, ".bmp" );
formattedDate = date.ToString( "d" );

using ( font =
new Font( FontFamily.Gene ricSansSerif, 12,
FontStyle.Regul ar )
) {
using ( bitmap = new Bitmap( 1, 1 ) ) {
using ( canvas = Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
textSize =
canvas.MeasureS tring( formattedDate, font );
}
}

using ( brush = new SolidBrush( Color.Black ) ) {
using ( bitmap = new Bitmap(

Convert.ToInt32 ( System.Math.Cei ling( textSize.Width ) ),

Convert.ToInt32 ( System.Math.Cei ling( textSize.Height ) )
) ) {

using ( canvas =
Graphics.FromIm age( bitmap ) ) {
canvas.TextRend eringHint =
TextRenderingHi nt.ClearTypeGri dFit;
canvas.DrawStri ng(
formattedDate,
font,
brush,
new PointF( 0, 0 )
);
}

//
bitmap.RotateFl ip( RotateFlipType. Rotate270FlipNo ne );

if ( File.Exists( result ) ) {
File.Delete( result );
}
bitmap.Save( result );
}
}
}

return result;
}

Oct 18 '07 #3
The good Cleartype font is Segoe UI. Also, It's not clear from the
code there what color depth of graphics object you have. You will need
32 bit coloring (aka, something with an alpha channel) for the
Cleartype to work.

Oct 18 '07 #4
On Oct 18, 11:16 am, not_a_commie <notacom...@gma il.comwrote:
The good Cleartype font is Segoe UI. Also, It's not clear from the
code there what color depth of graphics object you have. You will need
32 bit coloring (aka, something with an alpha channel) for the
Cleartype to work.
Hi, I actually got this to work, sorry for not following up sooner.
Instead of saving a bitmap, I saved as a jpg at 99% quality and that
cleared the problem right up. Which is weird, because I thought a
bitmap would be better quality (I was using 32bit with Alpha
bitmaps... the code was creating a new Bitmap instance from scratch).

Andy

Oct 25 '07 #5
Andy wrote:
Hi, I actually got this to work, sorry for not following up sooner.
Instead of saving a bitmap, I saved as a jpg at 99% quality and that
cleared the problem right up. Which is weird, because I thought a
bitmap would be better quality (I was using 32bit with Alpha
bitmaps... the code was creating a new Bitmap instance from scratch).
Assuming the same bitmap dimensions, an image saved as .bmp (or other
lossless format, such as .png or .tiff) _will_ be better quality than a
..jpeg file.

So, it's practically certain that there's more to the difference in your
code than simply changing the file format.

Pete
Oct 25 '07 #6

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

Similar topics

0
2092
by: Brian K | last post by:
I am new to Apache Batik and I am now doing a SVG Editor for my project. I use Java as programming language. I use Batik to generate the SVG from Java Graphics2D, as I would like to transform the SVG to other graphics formats (e.g. JPG, PNG, TIFF), an error occured, the error is that the graphics don't specify the size of graphics, so that even I can transform to JPG (for example), but the JPG file cannot display any graphics. Then I...
1
5328
by: James dean | last post by:
Could someone explain how this works. I think the graphics card is used to do blitting and drawing shapes like rectangles. How does it draw using the Graphics card on the PC and why is this feature left out of GDI+?. *** Sent via Developersdex http://www.developersdex.com ***
12
16413
by: Dr. Zharkov | last post by:
Hello. Inform, please, on what site it is possible to find materials on construction of the three-dimensional graphic of function z=f(x,y) with the help of Visual Basic .NET and GDI+? Beforehand many thanks for your answer. Best regards, Dr. V.A. Zharkov. Moscow, Russia.
5
1418
by: Tim | last post by:
hi I used to do this Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics gfx.FillEllipse blah blah blah to draw straight onto a form. but this is frowned up (slow).
6
3245
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
7
1496
by: dave | last post by:
Hello: I have appl with a LOT of graphics developed in GDI+ It runs on XP( SP 2 ) and tablet PC. Q: Does 3.0 have more efficient graphics API that will work on XP(SP2) and Tablet PC ? Thank you,
12
3600
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
11
1736
by: achiever | last post by:
I am a IIIrd electronics Engg student i want to know what is the role of graphics in c is it ok to spend a lot of time on learning c graphic or to start the new language like JAVA. Thanks in advance.
12
3898
by: gsal | last post by:
What would be the easiest way to go about offering 3D graphics for the purpose of rendering geometry? Suppose engineers (my co-workes) have to design some enclosure, nozzle, bracket, or whatever physical part/component, I would like to write a program where they can at least see the resulting geometry and navigate it, i.e., zoon-in/out, rotate, pan. On the side, I could have data entry fields with the input parameters and when something...
0
9566
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
9389
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
10149
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
10003
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...
1
9943
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7370
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
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.