我正在尝试在运行时使用线程定期增加 imageIcon 的高度和宽度。
我试过这个但没有成功
Image img = image.getImage();
BufferedImage bi = new BufferedImage(
img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
g.drawImage(img, 0, 0, 100, 100, null);
ImageIcon image = new ImageIcon(bi);
有人能帮我吗?谢谢
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ui {
public static void main(String[] args) {
JFrame frame = new JFrame();
//set imageicon
final ImageIcon image = new ImageIcon(
"C:\\Users\\User\\workspace\\Project\\images\\c.png");
JLabel imagelabel = new JLabel(image, JLabel.CENTER);
frame.add(imagelabel);
ScheduledExecutorService exec = Executors
.newSingleThreadScheduledExecutor();
exec.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// ---->How to increase height and width dynamically at runtime?
}
}, 0, 500, TimeUnit.MILLISECONDS);
}
}