Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to reset Graphics2D

Reply
Thread Tools

How to reset Graphics2D

 
 
Elliot
Guest
Posts: n/a
 
      03-23-2010
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
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      03-23-2010
On 3/23/2010 2:51 PM, Elliot wrote:
> 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

--

Knute Johnson
email s/nospam/knute2010/

 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      03-23-2010
On 3/23/2010 5:51 PM, Elliot wrote:
> HI
> I use the following code ...


Can you the procedure outlined in the example?
<http://java.sun.com/javase/6/docs/api/java/awt/Graphics2D.html#setTransform(java.awt.geom.AffineT ransform)>



 
Reply With Quote
 
Elliot
Guest
Posts: n/a
 
      03-24-2010
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-24-2010
On Tue, 23 Mar 2010 14:51:47 -0700 (PDT), Elliot <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>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? Im amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
 
Reply With Quote
 
Jeff Higgins
Guest
Posts: n/a
 
      04-03-2010
On 3/23/2010 5:51 PM, Elliot wrote:
> HI

[snip]
>
> How can I reset g2d to print normally?
>

A note on affine transforms from c.g.a.
<http://groups.google.com/group/comp.graphics.algorithms/msg/72754b9edcf73916?hl=en>
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Graphics2D: How to reset a BufferedImage with an Alpha chanel charlym Java 3 05-29-2006 03:14 PM
Painting with Graphics2D and an IndexColorModel... Michael C. Gilson Java 4 08-30-2003 11:43 PM
Interaction with Graphics2D drawing and buttons David Patterson Java 1 08-22-2003 08:24 AM
Graphics2D and Panels Wong Chee Wee Java 2 07-18-2003 01:31 PM



Advertisments