HighTechTalks DotNet Forums  

Graphics Help TranslateTransform and RotateTransform

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Graphics Help TranslateTransform and RotateTransform in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
standish22@hotmail.com
 
Posts: n/a

Default Graphics Help TranslateTransform and RotateTransform - 04-03-2007 , 11:45 AM






Hey, I'm confused!

I have a document that I want to print to a printer. I'm using inches
as my units. I got it working w/ Pixels, but my boss told me I have
to use Inches instead.

My question is how do you determine what the values need to be to pass
to
Graphics.TranslateTransform(dx,dy)? When I was using pixels I just
kept adjusting them, until finally after several hours found values
that seem to work.

I'm printing a document and I want to rotate it 180 degrees. (I know
I know, just turn the paper around..., but the paper has folds in
specific places, and printer also automatically folds the paper too.)

So my paper is 8.5x11

I've set Graphics.PageUnit = GraphicsUnit.Inch, and
Graphics.RotateTransform(180.0F)

How do I know what to put for Graphics.TranslateTransform(dx,dy)?
I've tried all kinds of values and my paper is just coming up blank???

Is it the same if my paper is 8.5x14?

Thanks in advance. I'm been mucking w/ this all day!


Reply With Quote
  #2  
Old   
Chris Taylor
 
Posts: n/a

Default Re: Graphics Help TranslateTransform and RotateTransform - 04-03-2007 , 02:03 PM






Hi,

The rotation is occuring around the 0,0 co-ordinate of the canvas
(screen/page) so a 180 degree rotation is resulting in the image being
rotated clock-wise around the top-left corner of the canvas. Assuming you
render the image at 0,0 on the page your image is now out to the left-top of
the page. To bring the image back into full view you would need to translate
it by the width and height of the image. To avoid all this I would rotate
around the center of the image and translate to the desired co-ordinates,
the one trick is to get the center of the image you will need the width and
height in inches and not pixels, the following should get you started.

private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Inch;

// Get device DPI to scale the image units
float dpiX = e.Graphics.DpiX;
float dpiY = e.Graphics.DpiY;

// Setup the transformation matrix
Matrix x = new Matrix();
// Translate to the desired co-ordinates
x.Translate(1, 1);

// Rotate about the center point of the image
// (Note we use the DPI to convert the image pixel size to inches)
x.RotateAt(180, new PointF((_img.Width / dpiX) / 2, (_img.Height /
dpiY) / 2));

// Apply the transformation to the graphics device
e.Graphics.Transform = x;

// Draw the image at 0, 0
e.Graphics.DrawImage(_img, 0, 0);
}


--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


<standish22 (AT) hotmail (DOT) com> wrote

Quote:
Hey, I'm confused!

I have a document that I want to print to a printer. I'm using inches
as my units. I got it working w/ Pixels, but my boss told me I have
to use Inches instead.

My question is how do you determine what the values need to be to pass
to
Graphics.TranslateTransform(dx,dy)? When I was using pixels I just
kept adjusting them, until finally after several hours found values
that seem to work.

I'm printing a document and I want to rotate it 180 degrees. (I know
I know, just turn the paper around..., but the paper has folds in
specific places, and printer also automatically folds the paper too.)

So my paper is 8.5x11

I've set Graphics.PageUnit = GraphicsUnit.Inch, and
Graphics.RotateTransform(180.0F)

How do I know what to put for Graphics.TranslateTransform(dx,dy)?
I've tried all kinds of values and my paper is just coming up blank???

Is it the same if my paper is 8.5x14?

Thanks in advance. I'm been mucking w/ this all day!



Reply With Quote
  #3  
Old   
standish22@hotmail.com
 
Posts: n/a

Default Re: Graphics Help TranslateTransform and RotateTransform - 04-03-2007 , 03:14 PM



What you say makes sense, but I can't seem to get it to work for me.
I'm printing a report. A blank page is still printing. I don't think
I can use e.Graphics.DrawImage(_img, 0, 0); , as I'm not printing an
image. And the Page.Draw function just accepts (Graphics,
RectangleF). Here's my code. Any ideas?


Private Sub Print180()
Dim prtRotatePrinter As New
DataDynamics.ActiveReports.Interop.SystemPrinter

prtRotatePrinter.StartJob("ActiveReports Document")
prtRotatePrinter.Graphics.PageUnit = GraphicsUnit.Inch

Dim dpiX As Single = prtRotatePrinter.Graphics.DpiX
Dim dpiY As Single = prtRotatePrinter.Graphics.DpiY

For Each pg As DataDynamics.ActiveReports.Document.Page In
g_Report180.Document.Pages
prtRotatePrinter.StartPage()
pg.Units =
DataDynamics.ActiveReports.Document.Units.Inches

Dim mtxMatrix As New System.Drawing.Drawing2D.Matrix
'Translate to the desired co-ordinates
mtxMatrix.Translate(1, 1)
mtxMatrix.RotateAt(180, New PointF((pg.Width / dpiX) / 2,
(pg.Height / dpiY) / 2))
prtRotatePrinter.Graphics.Transform = mtxMatrix

Dim rcPage As RectangleF = RectangleF.Empty
rcPage.Width = pg.Width
rcPage.Height = pg.Height
pg.Draw(prtRotatePrinter.Graphics, rcPage)

prtRotatePrinter.EndPage()
prtRotatePrinter.Graphics.ResetTransform()
Next

prtRotatePrinter.EndJob()

End Sub



Reply With Quote
  #4  
Old   
Chris Taylor
 
Posts: n/a

Default Re: Graphics Help TranslateTransform and RotateTransform - 04-05-2007 , 01:35 PM



Hi,

If you do no transformation at all does the document print? I have not
worked with the DataDynamics control you reference in the code but I would
guess that the
pg.Width and pg.Height are returned in pixels and maybe you require it in
inches, I am refering the the code from the following point on ...
Dim rcPage As RectangleF = RectangleF.Empty
rcPage.Width = pg.Width
rcPage.Height = pg.Height

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


<standish22 (AT) hotmail (DOT) com> wrote

Quote:
What you say makes sense, but I can't seem to get it to work for me.
I'm printing a report. A blank page is still printing. I don't think
I can use e.Graphics.DrawImage(_img, 0, 0); , as I'm not printing an
image. And the Page.Draw function just accepts (Graphics,
RectangleF). Here's my code. Any ideas?


Private Sub Print180()
Dim prtRotatePrinter As New
DataDynamics.ActiveReports.Interop.SystemPrinter

prtRotatePrinter.StartJob("ActiveReports Document")
prtRotatePrinter.Graphics.PageUnit = GraphicsUnit.Inch

Dim dpiX As Single = prtRotatePrinter.Graphics.DpiX
Dim dpiY As Single = prtRotatePrinter.Graphics.DpiY

For Each pg As DataDynamics.ActiveReports.Document.Page In
g_Report180.Document.Pages
prtRotatePrinter.StartPage()
pg.Units =
DataDynamics.ActiveReports.Document.Units.Inches

Dim mtxMatrix As New System.Drawing.Drawing2D.Matrix
'Translate to the desired co-ordinates
mtxMatrix.Translate(1, 1)
mtxMatrix.RotateAt(180, New PointF((pg.Width / dpiX) / 2,
(pg.Height / dpiY) / 2))
prtRotatePrinter.Graphics.Transform = mtxMatrix

Dim rcPage As RectangleF = RectangleF.Empty
rcPage.Width = pg.Width
rcPage.Height = pg.Height
pg.Draw(prtRotatePrinter.Graphics, rcPage)

prtRotatePrinter.EndPage()
prtRotatePrinter.Graphics.ResetTransform()
Next

prtRotatePrinter.EndJob()

End Sub




Reply With Quote
  #5  
Old   
standish22@hotmail.com
 
Posts: n/a

Default Re: Graphics Help TranslateTransform and RotateTransform - 04-06-2007 , 10:59 AM



Yes, it prints when there is no transformation. And it prints if I
rotate it say 30 degrees (not using the matrix, but using
Graphics.RotateTransform(30.0F))

I could get the original way I did it working with Pixels, but I was
told that it would work for all our customers based on screen/printer
settings.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.