Groups | Blog | Home
all groups > dotnet drawing api > april 2007 >

dotnet drawing api : Graphics objects --- passing the object vs the handle


Jeff
4/17/2007 1:20:41 PM
I have designed a set of classes which all accept a graphics object
and then render lines, rectanges, text, etc to that object. There is
a "parent" class which controls the instantiation of each class and
also calls the render method for each class, passing the form's
graphic object. This parent class also controls the zooming in/out
via a matrix. Everything works wonderfully.

I now have a need for an additional class which will accept a PDF file
and render it onto the same form. I want to build this class just
like the others, which means giving it a method which accepts a
Graphics object. I'm using a 3rd party control by Visage as part of
this new class. This Visage control even has a method called
"PaintToDC". The documentation for this method is as follows:

"PaintToDC (DC: HDC; em11, em12, em21, em22, dx, dy: Double)
Render the current page to the device context specifed from DC
parameter.the additional
parameters are for specifying the tranformation matrix used for
rendering.
By using transformation matrixes you will be able to scale/rotate/skew
etc the rendered page.
The default transformation matrix is 1,0,0,1,0,0"

The Problem: This control does not mesh with my current setup. The
"paint" does not scroll like the other classes. Is this because I'm
doing a GetHDC and then a ReleaseHDC on the Graphics object as opposed
to simply passing the Graphics object ByRef? If so, is there
something I can do within my "parent" class which will force this
Visage control to behave like my other classes when it comes to
scrolling and zooming?
Michael C
4/18/2007 12:00:00 AM
[quoted text, click to view]

AFAIK, you're stuck. It looks like the control does not use GDI+ which is
what is needed to use matrix transforms. It appears the control is using
plain old GDI which simply does not support this feature. You could paint to
a bitmap and then paint that bitmap to the form but the result will be poor.
The only solution I can think of is to find a control that does support GDI+
but I don't think that's going to be easy.

BTW, you should pass objects around ByVal generally.

Michael

Bob Powell [MVP]
4/21/2007 12:32:01 PM
I think rendering to a bitmap and then painting that with GDI+ is the only
way to go. I don't see why you think the result will be poor.. Am I missing
something important?

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


[quoted text, click to view]
Michael C
4/23/2007 12:00:00 AM
[quoted text, click to view]

He's talking about a PDF file which will print text. If the text is drawn
with anti-aliasing then it will anti-alias to the bitmap for normal
horizontal text. Drawing the bitmap zoomed and rotated will then modify that
anti-aliasing and potentially stretch/rotate it over several pixels. If the
text is drawn with non anti-aliasing then zooming it could make it blocky
and rotating it could make it pretty much unreadable.

You could potentially draw to a very high resolution bitmap and then scale
it down but this would present its own problems. Besided using a lot of
memory I think the result would be poor also as large fonts would not scale
down very well.

Michael

Doug Forster
4/27/2007 12:00:00 AM
Hi Jeff,

This is a fairly long shot but possibly the gdi world transform functions
might help. Never used them myself but look up SetWorldTransform. You would
have to PInvoke your way there and mimic your Graphics transform. Might be
completely incompatible with GDI+ but worth a look anyway.

Cheers
Doug Forster

AddThis Social Bookmark Button