Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would use <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics2D.html#drawImage%28java.awt.Image,%20java.awt.geom.AffineTransform,%20java.awt.image.ImageObserver%29" rel="noreferrer">Graphics2D.drawImage(image, affinetranform, imageobserver)</a>.</p> <p>The code example below rotates and translates an image to the center of the component. This is a screenshot of the result:</p> <p><img src="https://i.stack.imgur.com/WGlYu.png" alt="screenshot"></p> <pre><code> public static void main(String[] args) throws IOException { JFrame frame = new JFrame("Test"); frame.add(new JComponent() { BufferedImage image = ImageIO.read(new URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png")); @Override protected void paintComponent(Graphics g) { super.paintComponent(g); // create the transform, note that the transformations happen // in reversed order (so check them backwards) AffineTransform at = new AffineTransform(); // 4. translate it to the center of the component at.translate(getWidth() / 2, getHeight() / 2); // 3. do the actual rotation at.rotate(Math.PI/4); // 2. just a scale because this image is big at.scale(0.5, 0.5); // 1. translate the object so that you rotate it around the // center (easier :)) at.translate(-image.getWidth()/2, -image.getHeight()/2); // draw the image Graphics2D g2d = (Graphics2D) g; g2d.drawImage(image, at, null); // continue drawing other stuff (non-transformed) //... } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload