下面的Java程序要想实现旋转图片的功能,该怎么修改
importjava.awt.BorderLayout;importjava.awt.event.ActionEvent;importjava.awt.event.Act...
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class lianxi13 extends JFrame{
JPanel n,jPanel;
JLabel n1;
ImageIcon n3;
JButton n4,n5;
public lianxi13(){
super("fds");
setSize(600,600);
this.setVisible(true);
n=new JPanel();
n.setLayout(new BorderLayout());
n3=new ImageIcon("D://8.jpg");
n1=new JLabel(n3);
jPanel=new JPanel();
n.add(n1,BorderLayout.WEST);
n.add(jPanel,BorderLayout.EAST);
n4=new JButton("缩小");
n5=new JButton("扩大");
jPanel.add(n4,BorderLayout.EAST);
jPanel.add(n5,BorderLayout.WEST);
this.add(n);
n4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedImage bi = new BufferedImage((int)(n3.getIconWidth()*0.8),(int)(n3.getIconHeight()*0.8),BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(n3.getImage(), 0, 0, (int)(n3.getIconWidth()*0.8), (int)(n3.getIconHeight()*0.8),null);
bi.getGraphics().dispose();
n3.setImage(bi);
repaint();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
n5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedImage bi = new BufferedImage((int)(n3.getIconWidth()*1.2),(int)(n3.getIconHeight()*1.2),BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(n3.getImage(), 0, 0, (int)(n3.getIconWidth()*1.2), (int)(n3.getIconHeight()*1.2),null);
bi.getGraphics().dispose();
n3.setImage(bi);
repaint();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
public static void main(String[] args) {
new lianxi13();
}
} 展开
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class lianxi13 extends JFrame{
JPanel n,jPanel;
JLabel n1;
ImageIcon n3;
JButton n4,n5;
public lianxi13(){
super("fds");
setSize(600,600);
this.setVisible(true);
n=new JPanel();
n.setLayout(new BorderLayout());
n3=new ImageIcon("D://8.jpg");
n1=new JLabel(n3);
jPanel=new JPanel();
n.add(n1,BorderLayout.WEST);
n.add(jPanel,BorderLayout.EAST);
n4=new JButton("缩小");
n5=new JButton("扩大");
jPanel.add(n4,BorderLayout.EAST);
jPanel.add(n5,BorderLayout.WEST);
this.add(n);
n4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedImage bi = new BufferedImage((int)(n3.getIconWidth()*0.8),(int)(n3.getIconHeight()*0.8),BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(n3.getImage(), 0, 0, (int)(n3.getIconWidth()*0.8), (int)(n3.getIconHeight()*0.8),null);
bi.getGraphics().dispose();
n3.setImage(bi);
repaint();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
n5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedImage bi = new BufferedImage((int)(n3.getIconWidth()*1.2),(int)(n3.getIconHeight()*1.2),BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(n3.getImage(), 0, 0, (int)(n3.getIconWidth()*1.2), (int)(n3.getIconHeight()*1.2),null);
bi.getGraphics().dispose();
n3.setImage(bi);
repaint();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
public static void main(String[] args) {
new lianxi13();
}
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2个回答
展开全部
Image的getGraphics();返回来信强制转换为Graphics2D
调用Graphics2D的rotate(角度,旋转中心x坐标,y坐标)
调用Graphics2D的rotate(角度,旋转中心x坐标,y坐标)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-11-27
展开全部
百度
BufferedImage rotateImage(final BufferedImage bufferedimage
得到过程,添加按钮、设置事件。。。。。
BufferedImage rotateImage(final BufferedImage bufferedimage
得到过程,添加按钮、设置事件。。。。。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询