JAVA 读取 gif 图帧数

package com.yitianyike.utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

public class GifUtils {
	/**
	 * 获取GIF图的帧数
	 * @param data
	 * @return
	 * @throws IOException
	 */
	public static int gifFrameCount(byte data[]) throws IOException {
		ImageReader reader = (ImageReader) ImageIO.getImageReadersByFormatName("gif").next();
		ImageInputStream ciis = ImageIO.createImageInputStream(new ByteArrayInputStream(data));
		reader.setInput(ciis, false);
		int noi = reader.getNumImages(true);
		ciis.close();
		return noi;
	}
}

你可能感兴趣的:(JAVA,随笔)