在java程序中显示gif图片的代码
2018-07-20 来源:open-open
import java.awt.*; import java.awt.image.*; public class ImageCanvas extends Canvas { Image image; public ImageCanvas(String name) { MediaTracker media = new MediaTracker(this); image = Toolkit.getDefaultToolkit().getImage(name); media.addImage(image, 0); try { media.waitForID(0); } catch (Exception e) {} } public ImageCanvas(ImageProducer imageProducer) { image = createImage(imageProducer); } public void paint(Graphics g) { g.drawImage(image, 0,0, this); } public static void main(String argv[]) { if (argv.length < 1) { System.out.println ("usage: ImageCanvas.class [image file name]"); System.exit(0); } Frame frame = new Frame(argv[0]); frame.setLayout(new BorderLayout()); frame.add("Center", new ImageCanvas(argv[0])); frame.resize(400,400); frame.show(); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐