我有一个想要在 java 中调整大小的动画.GIF
图像,但是在尝试使用传统方法时,它似乎不起作用:
ImageIcon esclamativoMid = null;
//... search my file...
if(name.equalsIgnoreCase("esclamativo.gif"))
esclamativoMid = new ImageIcon(f.getAbsolutePath());
myEnumMap.put(Resolution.MID, esclamativoMid);
for(Resolution r: Resolution.values()){
if(r != Resolution.MID){
int w = esclamativoMid.getIconWidth()*(r.ordinal()+1)/2;
int h = esclamativoMid.getIconHeight()*(r.ordinal()+1)/2;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D)bi.createGraphics();
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
g2d.drawImage(esclamativoMid.getImage(), 0, 0, w, h, null);
myEnumMap.put(r, new ImageIcon(bi));
}
}
当我尝试使用该代码显示图像时:
new JLabel(myEnumMap.get(currentRes));
我得到.GIF
唯一的 if Resolution.MID
(即直接从文件加载的图像)。