G
Guest
Hi
Thanks for taking the time to read this post and offering any
suggestions/advice.
I have an owner drawn control that uses the standard setstyle method to
double buffer my painting. Everything works fine and looks as intended.
I am now in the process of expanded my rendering class to support internal
scrollable sections. I decided to do this by creating a wrapper class to
handle the painting. The wrapper class creates a new bitmap and passes the
graphics object from it to the original paint event of the renderer. It then
works out what section of the paint needs to be blitted onto the real canvas
and does so using the drawimage method.
It all works great apart from any text that is rendered to the new bitmap
looks really bad. It almost looks like it is bold but it is also nowhere
near as smooth as a bold font would be.
I believe I have ruled this down to the new bitmap being created with a
transparent background using black pixels. If I change the background to
white using the setpixel method and make it transparent using this colour (a
straight fillrectangle and anything other than white does not work) then
everything looks like it should.
Obviously this is a very slow method and totally unacceptable in the final
product.
Can anyone shed any light on the standard practice used to eliminate such
problems?
My current code in the paint method of the scrolling wrapper class is as
follows ....
'create canvas for child to paint on. we will extract the applicable
portion of the
'canvas and blit the render to the passed graphics object
Dim canvas As New System.Drawing.Bitmap(rect.Left + rect.Width, rect.Top + h)
canvas.SetResolution(g.DpiX, g.DpiY)
Dim gphcs As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(canvas)
Dim rect2 As New System.Drawing.Rectangle(rect.Left, rect.Top, canvas.Width,
canvas.Height)
Dim srcRect As New System.Drawing.Rectangle((rect.Left + _XOffset),
(rect.Top + _YOffset), rect.Width, rect.Height)
'***** this is the bit that corrects the problem, but it is very slow *****
'Dim x, y As Integer
'For x = srcRect.Left To srcRect.Right - 1 Step 1
' For y = srcRect.Top To srcRect.Bottom - 1 Step 1
' canvas.SetPixel(x, y, System.Drawing.Color.White)
' Next
'Next
'canvas.MakeTransparent(System.Drawing.Color.White)
_renderer.Paint(cp, gphcs, rect2)
g.DrawImage(canvas, rect, srcRect, Drawing.GraphicsUnit.Pixel)
gphcs.Dispose()
canvas.Dispose()
Thanks for taking the time to read this post and offering any
suggestions/advice.
I have an owner drawn control that uses the standard setstyle method to
double buffer my painting. Everything works fine and looks as intended.
I am now in the process of expanded my rendering class to support internal
scrollable sections. I decided to do this by creating a wrapper class to
handle the painting. The wrapper class creates a new bitmap and passes the
graphics object from it to the original paint event of the renderer. It then
works out what section of the paint needs to be blitted onto the real canvas
and does so using the drawimage method.
It all works great apart from any text that is rendered to the new bitmap
looks really bad. It almost looks like it is bold but it is also nowhere
near as smooth as a bold font would be.
I believe I have ruled this down to the new bitmap being created with a
transparent background using black pixels. If I change the background to
white using the setpixel method and make it transparent using this colour (a
straight fillrectangle and anything other than white does not work) then
everything looks like it should.
Obviously this is a very slow method and totally unacceptable in the final
product.
Can anyone shed any light on the standard practice used to eliminate such
problems?
My current code in the paint method of the scrolling wrapper class is as
follows ....
'create canvas for child to paint on. we will extract the applicable
portion of the
'canvas and blit the render to the passed graphics object
Dim canvas As New System.Drawing.Bitmap(rect.Left + rect.Width, rect.Top + h)
canvas.SetResolution(g.DpiX, g.DpiY)
Dim gphcs As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(canvas)
Dim rect2 As New System.Drawing.Rectangle(rect.Left, rect.Top, canvas.Width,
canvas.Height)
Dim srcRect As New System.Drawing.Rectangle((rect.Left + _XOffset),
(rect.Top + _YOffset), rect.Width, rect.Height)
'***** this is the bit that corrects the problem, but it is very slow *****
'Dim x, y As Integer
'For x = srcRect.Left To srcRect.Right - 1 Step 1
' For y = srcRect.Top To srcRect.Bottom - 1 Step 1
' canvas.SetPixel(x, y, System.Drawing.Color.White)
' Next
'Next
'canvas.MakeTransparent(System.Drawing.Color.White)
_renderer.Paint(cp, gphcs, rect2)
g.DrawImage(canvas, rect, srcRect, Drawing.GraphicsUnit.Pixel)
gphcs.Dispose()
canvas.Dispose()