資源描述:
《gif解碼和編碼操作庫(kù)源碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、GIF解碼和編碼操作庫(kù)源碼2007-01-1016:52GIF解碼和編碼操作庫(kù)源碼,共有四個(gè)類文件(請(qǐng)下載):1.AnimatedGifEncoder.java2.GifDecoder.java3.LZWEncoder.java4.NeuQuant.java簡(jiǎn)單應(yīng)用:?import?javax.imageio.ImageIO;import?java.io.*;import?java.awt.image.*;public?class?Testgif{?public?static?void?main(String?args[]){??
2、?try{?????????BufferedImage?src?=?ImageIO.read(new?File("c:/work/1.jpg"));?//?讀入文件?????????BufferedImage?src1?=?ImageIO.read(new?File("c:/work/2.jpg"));?//?讀入文件?????????BufferedImage?src2?=?ImageIO.read(new?File("c:/work/3.jpg"));?//?讀入文件????????????????????AnimatedGi
3、fEncoder?e?=?new?AnimatedGifEncoder();????????????????????e.setRepeat(0);????????????????????e.start("c:/work/laoma.gif");????????????????????e.setDelay(3000);???//?1?frame?per?sec????????????????????e.addFrame(src);????????????????????e.setDelay(1000);???????????????
4、?????e.addFrame(src1);????????????????????e.setDelay(100);????????????????????e.addFrame(src2);????????????????????e.finish();????????????}catch(IOException?e){????????????????e.printStackTrace();????????????}??}}下面的例子來(lái)自:http://blog.csdn.net/ideas/archive/2006/08/25/1
5、116198.aspx作者:?ideas1?多張jpg圖合成gif動(dòng)畫/**?????*?把多張jpg圖片合成一張?????*?@param?pic?String[]?多個(gè)jpg文件名?包含路徑?????*?@param?newPic?String?生成的gif文件名?包含路徑?????*/??private?synchronized?void?jpgToGif(String?pic[],?String?newPic)??{????????try??{????????????AnimatedGifEncoder?e?=?new?A
6、nimatedGifEncoder();?????????????e.setRepeat(0);????????????e.start(newPic);????????????BufferedImage?src[]?=?new?BufferedImage[pic.length];????????????for?(int?i?=?0;?i?
7、read(new?File(pic[i]));?//?讀入需要播放的jpg文件????????????????e.addFrame(src[i]);??//添加到幀中????????????}????????????e.finish();????????}?catch?(Exception?e)??{????????????System.out.println(?"jpgToGif?Failed:");????????????e.printStackTrace();????????}????}2?gif動(dòng)畫分解成多張jpg????
8、/**?*//**?????*?把gif圖片按幀拆分成jpg圖片??????????????*?@param?gifName?String?小gif圖片(路徑+名稱)?????*?@param?path?String?生成小jpg圖片的路徑????