如何调整在类路径资源中选择的标签中的图像大小?
How do I resize an image in a label that's selected in a classpath resource?
这是代码
btnVoltar.setIcon(new ImageIcon(AdicionarRefeição1.class.getResource("/icons/Back Icon.png")));
我想调整它的大小以适合标签,但它太大了。
您可以在此处尝试此代码,但此 post 与 Whosebug
重复
private ImageIcon image; // where in your case it's your class resource
Image IMG = image.getImage(); // transform it
Image newimg = IMG.getScaledInstance(200, 200, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
//Change the 200,200 to the number you prefer to resize it to
image = new ImageIcon(newimg); // transform it back
这是代码
btnVoltar.setIcon(new ImageIcon(AdicionarRefeição1.class.getResource("/icons/Back Icon.png")));
我想调整它的大小以适合标签,但它太大了。
您可以在此处尝试此代码,但此 post 与 Whosebug
重复private ImageIcon image; // where in your case it's your class resource
Image IMG = image.getImage(); // transform it
Image newimg = IMG.getScaledInstance(200, 200, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
//Change the 200,200 to the number you prefer to resize it to
image = new ImageIcon(newimg); // transform it back