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. 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
"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/>
"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
"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/>
"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.
"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/>
'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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: ljlevend |
last post by:
Is there a way to determine whether font supports ClearType?
Thanks,
Lance
|
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...
|
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...
|
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
|
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.
...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |