代码如下
package awt; import java.awt.*; import java.net.URL; import javax.swing.*; import awt.RotateImage.MyCanvas; public class TiltImage extends JFrame{ private Image img; private MyCanvas canvasPanel=null; public TiltImage() { initialize(); //shear方法倾斜 } private void initialize() { URL imgUrl=TiltImage.class.getResource("picture.jpg"); img=Toolkit.getDefaultToolkit().getImage(imgUrl); canvasPanel=new MyCanvas(); this.setBounds(100,100,400,350); add(canvasPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("图片倾斜"); } public static void main(String[]args) { new TiltImage().setVisible(true); } class MyCanvas extends JPanel{ public void paint(Graphics g) { Graphics2D g2=(Graphics2D)g; g2.shear(0.3,0); g2.drawImage(img, 70,10,300, 200,this); } } }