如何在JLabel中调整Image / IconImage的大小? [英] How to resize Image/IconImage in JLabel?
本文介绍了如何在JLabel中调整Image / IconImage的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
String s = "/Applications/Asphalt6.app";
JFileChooser chooser = new JFileChooser();
File file = new File(s);
Icon icon = chooser.getIcon(file);
// show the icon
JLabel ficon = new JLabel(s, icon, SwingConstants.LEFT);
现在,从图标中提取的图像非常小。如何调整大小?
Now, the image extracted from the icon is really small. How can I resize it?
推荐答案
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
class BigIcon {
public static void main(String[] args) {
JFileChooser chooser = new JFileChooser();
File f = new File("BigIcon.java");
Icon icon = chooser.getIcon(f);
int scale = 4;
BufferedImage bi = new BufferedImage(
scale*icon.getIconWidth(),
scale*icon.getIconHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.scale(scale,scale);
icon.paintIcon(null,g,0,0);
g.dispose();
JOptionPane.showMessageDialog(
null,
new JLabel(new ImageIcon(bi)));
}
}
这篇关于如何在JLabel中调整Image / IconImage的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文