【发布时间】:2013-02-09 20:33:26
【问题描述】:
我有一个动画 .GIF 图像,我想在 java 中调整大小,但是当尝试使用传统方法时,它似乎不起作用:
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));
只有当Resolution.MID(即直接从文件加载的图像)时,我才会得到.GIF。
【问题讨论】:
标签: java image draw gif image-resizing