473,385 Members | 1,606 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,385 software developers and data experts.

cleartype - gdi

I was banging my head against the wall with this code in a sub:

Dim writing As New Bitmap(ctrl.Width, ctrl.Height)
Dim surface As Graphics = Graphics.FromImage(writing)
surface.DrawString(textToWrite, font1, Brushes.Black, 0, 0)
ctrl.Image = writing

It produced terribly blocky text.

I finally added:
surface.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.SingleBitPer PixelGridFit

Which cleared up the mess.

I then got thinking - both machines I was testing it on have lcd's and
cleartype enabled in the control panel. I went and switched it off, and
tried the basic code again and it worked without producing the weird text.

See piccy:
http://www.psatracker.co.uk/pics/Cleartype.gif

If you create a graphics object in a controls paint event and use the same
code to draw a string on that then you don't get the blocky text.

Weird. Anyone know how to detect if the user has Cleartype switched on? I'm
using the cleartpye tuning wizard in the control panel to enable cleartype
if it is relevant.
Nov 21 '05 #1
7 1989
hoppy <me@null.invalid> wrote in
news:Xn***************************@194.117.143.53:
I was banging my head against the wall with this code in a sub:

Dim writing As New Bitmap(ctrl.Width, ctrl.Height)
Dim surface As Graphics = Graphics.FromImage(writing)
surface.DrawString(textToWrite, font1, Brushes.Black, 0, 0)
ctrl.Image = writing

It produced terribly blocky text.

I finally added:
surface.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.SingleBitPer PixelGridFit

Which cleared up the mess.

I then got thinking - both machines I was testing it on have lcd's and
cleartype enabled in the control panel. I went and switched it off,
and tried the basic code again and it worked without producing the
weird text.

See piccy:
http://www.psatracker.co.uk/pics/Cleartype.gif

If you create a graphics object in a controls paint event and use the
same code to draw a string on that then you don't get the blocky text.

Weird. Anyone know how to detect if the user has Cleartype switched
on? I'm using the cleartpye tuning wizard in the control panel to
enable cleartype if it is relevant.

got help:

HKEY_CURRENT_USER\Control Panel\Desktop\FontSmoothingType
Nov 21 '05 #2
"hoppy" <me@null.invalid> schrieb:
Dim writing As New Bitmap(ctrl.Width, ctrl.Height)
Dim surface As Graphics = Graphics.FromImage(writing)
surface.DrawString(textToWrite, font1, Brushes.Black, 0, 0)
ctrl.Image = writing

It produced terribly blocky text.

I finally added:
surface.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.SingleBitPer PixelGridFit

Which cleared up the mess.

I then got thinking - both machines I was testing it on have lcd's and
cleartype enabled in the control panel. I went and switched it off, and
tried the basic code again and it worked without producing the weird text.

See piccy:
http://www.psatracker.co.uk/pics/Cleartype.gif

If you create a graphics object in a controls paint event and use the same
code to draw a string on that then you don't get the blocky text.


The picture looks as if you were drawing the same string several times at
the same position without clearing the surface you are drawing on.
ClearType will add RGB values to the surrounding pixels, and thus drawing
the same string at the same position more than one time will lead to ugly
results.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:eK**************@TK2MSFTNGP12.phx.gbl:
"hoppy" <me@null.invalid> schrieb:
Dim writing As New Bitmap(ctrl.Width, ctrl.Height)
Dim surface As Graphics = Graphics.FromImage(writing)
surface.DrawString(textToWrite, font1, Brushes.Black, 0, 0)
ctrl.Image = writing

It produced terribly blocky text.

I finally added:
surface.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.SingleBitPer PixelGridFit

Which cleared up the mess.

I then got thinking - both machines I was testing it on have lcd's
and cleartype enabled in the control panel. I went and switched it
off, and tried the basic code again and it worked without producing
the weird text.

See piccy:
http://www.psatracker.co.uk/pics/Cleartype.gif

If you create a graphics object in a controls paint event and use the
same code to draw a string on that then you don't get the blocky
text.


The picture looks as if you were drawing the same string several times
at the same position without clearing the surface you are drawing on.
ClearType will add RGB values to the surrounding pixels, and thus
drawing the same string at the same position more than one time will
lead to ugly results.


It happens when you draw the string once.

This (complete) code produces the linked text when cleartype is on.

http://www.psatracker.co.uk/pics/test.bmp
Imports System.Drawing
Module Module1
Sub Main()
Dim bm As New Bitmap(450, 120)
Dim g As Graphics = Graphics.FromImage(bm)
Dim f As Font = New Font("Tahoma", 9.75!, FontStyle.Regular)
Dim s As String
s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit," & _
"sed do eiusmod tempor incididunt ut labore et dolore ma" & _
"gna aliqua. Ut enim ad minim veniam, quis nostrud exerc" & _
"itation ullamco laboris nisi ut aliquip ex ea commodo c" & _
"onsequat. Duis aute irure dolor in reprehenderit in vol" & _
"uptate velit esse cillum dolore eu fugiat nulla pariatu" & _
"r. Excepteur sint occaecat cupidatat non proident, sunt" & _
"in culpa qui officia deserunt mollit anim id est laborum"

Dim sf As StringFormat = _
CType(StringFormat.GenericDefault.Clone(), StringFormat)

Dim recF As New RectangleF(0, 0, 450, 120)
g.DrawString(s, f, Brushes.Black, recF, sf)
bm.Save("C:\test.bmp")
End Sub
End Module
It looks normal when cleartype is off.
Not to worry, I can fix it by testing this key to see if cleartype is on
(value = 2):

HKEY_CURRENT_USER\Control Panel\Desktop\FontSmoothingType

and then setting
g.TextRenderingHint to something appropriate such as:
System.Drawing.Text.TextRenderingHint.SingleBitPer PixelGridFit
Nov 21 '05 #4
"hoppy" <no***@invalid.null> schrieb:
This (complete) code produces the linked text when cleartype is on.

http://www.psatracker.co.uk/pics/test.bmp
Imports System.Drawing
Module Module1
Sub Main()
Dim bm As New Bitmap(450, 120)
Dim g As Graphics = Graphics.FromImage(bm)
Dim f As Font = New Font("Tahoma", 9.75!, FontStyle.Regular)
Dim s As String
s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit," & _
"sed do eiusmod tempor incididunt ut labore et dolore ma" & _
"gna aliqua. Ut enim ad minim veniam, quis nostrud exerc" & _
"itation ullamco laboris nisi ut aliquip ex ea commodo c" & _
"onsequat. Duis aute irure dolor in reprehenderit in vol" & _
"uptate velit esse cillum dolore eu fugiat nulla pariatu" & _
"r. Excepteur sint occaecat cupidatat non proident, sunt" & _
"in culpa qui officia deserunt mollit anim id est laborum"

Dim sf As StringFormat = _
CType(StringFormat.GenericDefault.Clone(), StringFormat)

Dim recF As New RectangleF(0, 0, 450, 120)
g.DrawString(s, f, Brushes.Black, recF, sf)
bm.Save("C:\test.bmp")
End Sub
End Module


As I already said, don't forget to clear the bitmap ('g.Clear(Color.White)')
before drawing the string -- this will fix the problem. Otherwise a
transparent PNG will be saved and many applications are not able to display
these images correctly.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:uK**************@tk2msftngp13.phx.gbl:
"hoppy" <no***@invalid.null> schrieb:
This (complete) code produces the linked text when cleartype is on.

http://www.psatracker.co.uk/pics/test.bmp
Imports System.Drawing
Module Module1
Sub Main()
Dim bm As New Bitmap(450, 120)
Dim g As Graphics = Graphics.FromImage(bm)
Dim f As Font = New Font("Tahoma", 9.75!, FontStyle.Regular)
Dim s As String
s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit," & _
"sed do eiusmod tempor incididunt ut labore et dolore ma" & _
"gna aliqua. Ut enim ad minim veniam, quis nostrud exerc" & _
"itation ullamco laboris nisi ut aliquip ex ea commodo c" & _
"onsequat. Duis aute irure dolor in reprehenderit in vol" & _
"uptate velit esse cillum dolore eu fugiat nulla pariatu" & _
"r. Excepteur sint occaecat cupidatat non proident, sunt" & _
"in culpa qui officia deserunt mollit anim id est laborum"

Dim sf As StringFormat = _
CType(StringFormat.GenericDefault.Clone(), StringFormat)

Dim recF As New RectangleF(0, 0, 450, 120)
g.DrawString(s, f, Brushes.Black, recF, sf)
bm.Save("C:\test.bmp")
End Sub
End Module


As I already said, don't forget to clear the bitmap
('g.Clear(Color.White)') before drawing the string -- this will fix
the problem. Otherwise a transparent PNG will be saved and many
applications are not able to display these images correctly.


hmm ok, that works. sorry wasn't paying attention.

I'm actually then using the bitmap to make a cursor for drag and drop
(cursor is an image of the text being dragged). If I blank out the back
beforehand then I'll get a white background. For now I'll use the
workaround. I guess what I should do is create the cursor properly from a
bitmap and a mask, I'll have to read up on that.
Nov 21 '05 #6
"hoppy" <no***@invalid.null> schrieb:
I'm actually then using the bitmap to make a cursor for drag and drop
(cursor is an image of the text being dragged). If I blank out the back
beforehand then I'll get a white background. For now I'll use the
workaround. I guess what I should do is create the cursor properly from a
bitmap and a mask, I'll have to read up on that.


When creating a cursor I would not use ClearType rendering. As you already
know you can change the text rendering mode by setting the 'Graphics'
object's 'TextRenderingHint' property to an appropriate value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

'This will create a cursor from a part of the control
'Assume gph is the Graphics object for the control
'ulcornerX, ulcornerY, width, and height descripe what part of the control
you want to make a cursor from

Dim rect As New Rectangle(ulcornerX, ulcornerY,width, height)
Dim cursorbitmap as New Bitmap(rect.Width, rect.Height)
cursorbitmap = CopyRect(gph, rect)
cursorbitmap.MakeTransparent(backgroundcolor)
dim ptrCur as IntPtr = cursorbitmap.GetHicon
dim ps Point = Me.PointToScreen(New Point(0, t))
dim cp as New Point(ulcornerXStartCursorPosition,
ulcornerYStartCursorPosition)
dim cc as New Rectangle(ulcornerX, ulcornerY, WidthofallowedCursormove,
HeightofAllowedCursorMove) 'defines the boundaries that the cursor can be
moved
Me.Cursor = New Cursor(ptrCur)
Me.Cursor.Position = cp
Me.Cursor.Clip = cc
DeleteObject(ptrCur)

--
Dennis in Houston
"hoppy" wrote:
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
news:uK**************@tk2msftngp13.phx.gbl:
"hoppy" <no***@invalid.null> schrieb:
This (complete) code produces the linked text when cleartype is on.

http://www.psatracker.co.uk/pics/test.bmp
Imports System.Drawing
Module Module1
Sub Main()
Dim bm As New Bitmap(450, 120)
Dim g As Graphics = Graphics.FromImage(bm)
Dim f As Font = New Font("Tahoma", 9.75!, FontStyle.Regular)
Dim s As String
s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit," & _
"sed do eiusmod tempor incididunt ut labore et dolore ma" & _
"gna aliqua. Ut enim ad minim veniam, quis nostrud exerc" & _
"itation ullamco laboris nisi ut aliquip ex ea commodo c" & _
"onsequat. Duis aute irure dolor in reprehenderit in vol" & _
"uptate velit esse cillum dolore eu fugiat nulla pariatu" & _
"r. Excepteur sint occaecat cupidatat non proident, sunt" & _
"in culpa qui officia deserunt mollit anim id est laborum"

Dim sf As StringFormat = _
CType(StringFormat.GenericDefault.Clone(), StringFormat)

Dim recF As New RectangleF(0, 0, 450, 120)
g.DrawString(s, f, Brushes.Black, recF, sf)
bm.Save("C:\test.bmp")
End Sub
End Module


As I already said, don't forget to clear the bitmap
('g.Clear(Color.White)') before drawing the string -- this will fix
the problem. Otherwise a transparent PNG will be saved and many
applications are not able to display these images correctly.


hmm ok, that works. sorry wasn't paying attention.

I'm actually then using the bitmap to make a cursor for drag and drop
(cursor is an image of the text being dragged). If I blank out the back
beforehand then I'll get a white background. For now I'll use the
workaround. I guess what I should do is create the cursor properly from a
bitmap and a mask, I'll have to read up on that.

Nov 21 '05 #8

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

Similar topics

23
by: Martin! | last post by:
does anyone know if WinXP by default uses 'Cleartype' or 'Standard'. i noticed that using 'standard' all font-families (except sans-serif) are NOT anti-aliassed, while with 'cleartype' everything...
2
by: ljlevend | last post by:
Is there a way to determine whether font supports ClearType? Thanks, Lance
0
by: cloabell | last post by:
I would like to provide the option to enable ClearType in a RichTextBox, even when the system-wide setting is disabled. No matter what I do, my RTF box always repaints its text according to the...
0
by: Max Power | last post by:
MS Cleartype Tuner not so good on older 800x600 displays (older VGA, pre-I2S Card to Monitor telemetry)... PS: Did anyone notice that the Control Panel listing was somehow sorted by the IE7...
4
by: Residential Area Freak | last post by:
How do I disable programmatically the cleartype function in IE 7 for my web apps? Are there new HTML-Tags or JavaScript functions to disable cleartype in the development? Best regards pP
5
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
Is there any way to do the following: 1. Determine whether ClearType is enabled by the system (under Display Properties - Effects in WinXP). 2. Determine whether a font supports ClearType. ...
7
by: active | last post by:
In control panel/Display/Appearance/Effects if : 'Use the following method to smooth edges of screen fonts' is checked and ClearType is selected in the combobox (no problem if Standard is...
1
by: Wayne | last post by:
Is there some way of turning off "ClearType" in the Access 2007 runtime? Perhaps a registry tweak? On all of my LCD screens "ClearType" makes fonts, especially bold fonts, in Access appear...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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
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...

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.