j2ee协会吧 关注:77贴子:625
  • 0回复贴,共1

有没有大神帮我把下面的图片的旋转和剪切函数补充一下???

只看楼主收藏回复

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Liuq extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JPanel jPanel1;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
JButton jButton1,jButton2,jButton3,jButton4;
int width,height;
public Liuq() {
super("图片大小");
this.setSize(600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
image = Toolkit.getDefaultToolkit().getImage("src/1.jpg.jpg");
jLabel=new JLabel();
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
jLabel.updateUI();
jButton1 = new JButton("变大");
jButton2 = new JButton("变小");
jButton3 = new JButton("旋转");
jButton4 = new JButton("剪切");
jPanel1 = new JPanel();
jPanel1.add(jButton1);
jPanel1.add(jButton2);
jPanel1.add(jButton3);
jPanel1.add(jButton4);
this.add(jLabel, BorderLayout.NORTH);
this.add(jPanel1, BorderLayout.SOUTH);
this.setVisible(true);
width=image.getWidth(null);
height=image.getHeight(null);
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
big();
}
});
jButton2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
small();
}
});
jButton3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
rotate();
}
});
jButton4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
cut();
}
});
}
double zoom=1.0;
public void big(){
zoom+=0.2;
float www=(float)(width*zoom);
float hhh=(float)(height*zoom);
System.out.println(www+""+hhh);
if(www<1||hhh<1){
System.out.println("Size too small.");
return;
}
if(www>3000||hhh>3000){
zoom-=0.2;
System.out.println("Size too big.");
return;
}
//image = image.getScaledInstance((int)www,(int)hhh,Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image.getScaledInstance((int)www,(int)hhh,Image.SCALE_DEFAULT));
jLabel.setIcon(imageIcon);
}
public void small(){
zoom-=0.2;
float www=(float)(width*zoom);
float hhh=(float)(height*zoom);
System.out.println(www+""+hhh);
if(www<1||hhh<1){
zoom+=0.2;
System.out.println("Size too small.");
return;
}
//image = image.getScaledInstance((int)www,(int)hhh,Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image.getScaledInstance((int)www,(int)hhh,Image.SCALE_DEFAULT));
jLabel.setIcon(imageIcon);
}
public void rotate(){
}
public void cut(){
}
public static void main(String[] args){
new Liuq();
}
}


IP属地:陕西1楼2016-07-05 11:20回复