How to reset Graphics2D

Discussion in 'Java' started by Elliot, Mar 23, 2010.

  1. Elliot

    Elliot Guest

    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
     
    Elliot, Mar 23, 2010
    #1
    1. Advertising

  2. 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/
     
    Knute Johnson, Mar 23, 2010
    #2
    1. Advertising

  3. Elliot

    Jeff Higgins Guest

    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.AffineTransform)>
     
    Jeff Higgins, Mar 23, 2010
    #3
  4. Elliot

    Elliot Guest

    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
     
    Elliot, Mar 24, 2010
    #4
  5. Elliot

    Roedy Green Guest

    On Tue, 23 Mar 2010 14:51:47 -0700 (PDT), Elliot <>
    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?” I’m amazed how many theoretical arguments evaporate when faced with this question.
    ~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
     
    Roedy Green, Mar 24, 2010
    #5
  6. Elliot

    Jeff Higgins Guest

    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>
     
    Jeff Higgins, Apr 3, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wong Chee Wee

    Graphics2D and Panels

    Wong Chee Wee, Jul 17, 2003, in forum: Java
    Replies:
    2
    Views:
    516
    Wong Chee Wee
    Jul 18, 2003
  2. David Patterson
    Replies:
    1
    Views:
    445
    David Patterson
    Aug 22, 2003
  3. Michael C. Gilson
    Replies:
    4
    Views:
    979
    Ken DeLong
    Aug 31, 2003
  4. Amadeus
    Replies:
    0
    Views:
    506
    Amadeus
    Sep 2, 2003
  5. charlym
    Replies:
    3
    Views:
    4,464
    Oliver Wong
    May 29, 2006
Loading...

Share This Page