2011-07-26 9 views

答えて

5

はい、あなたは左下隅から描画するAffineTransformを使用することができます。

Screenshot

コード:

public static void main(String[] args) { 

    JFrame frame = new JFrame("Test"); 

    frame.add(new JComponent() { 
     @Override 
     protected void paintComponent(Graphics g) { 
      super.paintComponent(g); 

      Graphics2D g2d = (Graphics2D) g; 

      // save the "old" transform 
      AffineTransform old = g2d.getTransform(); 

      // update graphics object with the inverted y-transform 
      g2d.translate(0, getHeight() - 1); 
      g2d.scale(1, -1); 

      // draw what you want 
      g2d.drawLine(0, 0, 300, 200); 

      // restore the old transform 
      g2d.setTransform(old); 
     } 
    }); 

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setSize(400, 300); 
    frame.setVisible(true); 
} 
+0

クール豆の男のおかげで、私は見ているだろう。 – Ben

+0

私の画像が上下が逆の場合を除き、どうもありがとうございます:/。将来のユーザーのためのFYI AffineTransformは 'java.awt.geom.AffineTransform'にあります。 – Ben

+0

はい、「デフォルト」変換で何かを描画したい場合は、変更する前に(super.paintComponent(g);の直後に)行う必要があるので、変換はグラフィックスオブジェクトへの呼び出しを変換します。 ) – dacwe

関連する問題