用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

gif解码器实例

2014-04-16 作者: 小蜜锋举报

[android]代码库

package com.ray.test.gif;

import java.io.File;
import java.io.FileNotFoundException;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class GifDecoder {

	private static final String MYTAG = "Ray";
	private static final String CLASS_NAME = "GifDecoder";

	public interface DecodeResult {
		public void onDecodeFinished(int count);
	}

	private static Gif sGif;
	private static DecodeResult sListener;
	private static boolean sIsReady = false;

	static void decode(String filePath, DecodeResult result) throws FileNotFoundException {
		File f = new File(filePath);
		if (f.exists()) {
			sListener = result;
			sIsReady = false;
			sGif = null;
			WorkThread thread = new WorkThread(filePath);
			thread.start();
		} else
			throw new FileNotFoundException("can not find file:" + filePath);
	}

	static Gif getImage() {
		return sGif;
	}

	private static void onDecodeFinished(String count) {
		Log.d(MYTAG, CLASS_NAME + ": onDecodeFinished, count = " + count);
		int c = Integer.parseInt(count);
		getFrames(c);
		if(c == 0)
			mHandler.obtainMessage(c).sendToTarget();
	}

	private static void getFrames(int idx) {
		if(idx == 0)
			sGif = new Gif(getWidth(), getHeight());
		sGif.addFrame(getDelay(idx), getColors(idx), getUserInput(idx));
	}

	private static class WorkThread extends Thread {
		private String mPath;

		public WorkThread(String path) {
			mPath = path;
		}

		@Override
		public void run() {
			doDecode(mPath);
		}
	}

	private static Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			sListener.onDecodeFinished(msg.what);
		}
	};

	private static native void doDecode(String path);

	private static native int getWidth();

	private static native int getHeight();

	private static native int getDelay(int index);

	private static native boolean getUserInput(int index);

	private static native int[] getColors(int index);
}

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...