本文介绍了Java绘制GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Java Graphics API绘制GIF,但无法使用下面的代码成功绘制GIF.仅绘制了GIF的第一张图片或缩略图,但无法播放.
I'm trying to draw a GIF using the Java Graphics API, but I'm not able to successfully draw a GIF using my below code. Only the first image or thumbnail of the GIF is drawn but it doesn't play.
public void paintComponent(Graphics g){
super.paintComponent(g);
BufferedImage img = null;
try {
URL url = new URL("GIF URL");
img = ImageIO.read(url);
} catch (Exception e) {
}
g.drawImage(img, 5, 5, this);
}
基本上,我正在为登录屏幕创建图形,并且想要绘制一个循环的GIF.
Essentially I am creating graphics for a login screen and I want to draw a GIF that loops.
更新了我的代码并稍微更改了问题.
Updated my code and changed the question a bit.
推荐答案
您可以将gif加载到BufferedImage对象中.然后我们将缓冲的图像绘制到您的swing组件上
You can load a gif into a BufferedImage object.Then we paint the buffered image onto your swing component
还必须更好地重写paintComponent方法
Also one must better override the paintComponent method
这篇关于Java绘制GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!