How to reset Graphics2D

E

Elliot

HI
I use the following code to print some barcode which is rotated 90
degrees down the left side of a page which prints in landscape:

g2d.translate(haX + intBarCodeHeight,
0);
g2d.rotate(90.0 * Math.PI / 180.0); // convert
radians, which are about 57 degrees, to degrees
g2d.drawImage(img,haY,
0,intBarCodeWidth,intBarCodeHeight, null);

The barcode prints correctly; however anything that prints after it is
also rotated and offset (due to g2d.translate(...) I imagine.)

I've tried variations on all of the following with no joy.

// g2d = (Graphics2D) g; // Bring 2D contect back
to normal rotations
// g2d.translate(pf.getImageableX(),
pf.getImageableY());
// g2d.rotate(360.0 * Math.PI / 180.0); // Bring
2D contect back to normal rotations

How can I reset g2d to print normally?

Thanks in advance.

Elliot
 
K

Knute Johnson

HI
I use the following code to print some barcode which is rotated 90
degrees down the left side of a page which prints in landscape:

g2d.translate(haX + intBarCodeHeight,
0);
g2d.rotate(90.0 * Math.PI / 180.0); // convert
radians, which are about 57 degrees, to degrees
g2d.drawImage(img,haY,
0,intBarCodeWidth,intBarCodeHeight, null);

The barcode prints correctly; however anything that prints after it is
also rotated and offset (due to g2d.translate(...) I imagine.)

I've tried variations on all of the following with no joy.

// g2d = (Graphics2D) g; // Bring 2D contect back
to normal rotations
// g2d.translate(pf.getImageableX(),
pf.getImageableY());
// g2d.rotate(360.0 * Math.PI / 180.0); // Bring
2D contect back to normal rotations

How can I reset g2d to print normally?

Thanks in advance.

Elliot

Save it before you mutate it.

AffineTransform at = g2d.getTransform();

// mutate

g2d.setTransform(at);

// do something you don't want twisted up
 
E

Elliot

Knute,

You are the man.

Java is not really my language; I wanted to save the original graphics
context but didn't know how.

This did it

Thanks

Elliot
 
R

Roedy Green

How can I reset g2d to print normally?

see http://mindprod.com/jgloss/affinetransform.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, “How would I develop if it were my money?” I’m amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
 

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top