java 修改图片 大小

 

java修改图片大小的代码如下:

 

File f = new File("C://180.jpg");

BufferedImage bimg = ImageIO.read(f);

Image image = bimg.getScaledInstance(width, height, Image.SCALE_SMOOTH);

BufferedImage target = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);

Graphics g = target.getGraphics();  

g.drawImage(image, 0, 0, null);

g.dispose(); 

ImageIO.write(target, "jpg", new File("C://18011.jpg")); 

 

 

已标记关键词 清除标记
import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class ButtonFrame extends JFrame { private JButton plainJButton;//button with just text private JButton fancyJButton;//button with icons //ButtonFrame adds JButtons to JFrame public ButtonFrame() { super("Testing Buttons"); setLayout(new FlowLayout());//set frame layout plainJButton=new JButton("Plain Button");//button with text add(plainJButton);//add plainJButton to JFrame Icon bug1=new ImageIcon(getClass().getResource("t013971ecacef25bf25.jpg")); Icon bug2=new ImageIcon(getClass().getResource("t019bbb4841bb28712f.jpg")); fancyJButton=new JButton("Fancy Button",bug1);//set image fancyJButton.setRolloverIcon(bug2); add(fancyJButton);//add fancyJButton to JFrame //create new ButtonHandler for button event handling ButtonHandler handler=new ButtonHandler(); fancyJButton.addActionListener(handler); plainJButton.addActionListener(handler); }//end buttonFrame constructor //inner class for button event handling private class ButtonHandler implements ActionListener { //handle button event public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed:%s", event.getActionCommand())); }//end method actionPerformed }//end private inner class buttonHandler }//end class ButtonFrame 根据书上的代码加入了图片,但是图片总是太大,不满足我的需求,请问怎样或者说用什么函数才能调整图片大小呢?请大神指教,帮我修改一下上面的代码
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页