@SuppressWarnings("deprecation") public GifAnimationDrawable(InputStream is, boolean inline) throws IOException { super(); InputStream bis = is; if (!BufferedInputStream.class.isInstance(bis)) bis = new BufferedInputStream(is, 32768); decoded = false; mGifDecoder = new GifDecoder(); mGifDecoder.read(bis); mTmpBitmap = mGifDecoder.getFrame(0); android.util.Log.v( "GifAnimationDrawable", "===>Lead frame: [" + width + "x" + height + "; " + mGifDecoder.getDelay(0) + ";" + mGifDecoder.getLoopCount() + "]"); height = mTmpBitmap.getHeight(); width = mTmpBitmap.getWidth(); addFrame(new BitmapDrawable(mTmpBitmap), mGifDecoder.getDelay(0)); setOneShot(mGifDecoder.getLoopCount() != 0); setVisible(true, true); if (inline) { loader.run(); } else { new Thread(loader).start(); } }
public Gif(PApplet parent, String filename) { // this creates a fake image so that the first time this // attempts to draw, something happens that's not an exception super(1, 1, ARGB); this.parent = parent; // create the GifDecoder GifDecoder gifDecoder = createDecoder(parent, filename); // fill up the PImage and the delay arrays frames = extractFrames(gifDecoder); delays = extractDelays(gifDecoder); // get the GIFs repeat count repeatSetting = gifDecoder.getLoopCount(); // re-init our PImage with the new size super.init(frames[0].width, frames[0].height, ARGB); jump(0); parent.registerMethod("dispose", this); // and now, make the magic happen runner = new Thread(this); runner.start(); }
public void run() { final int n = mGifDecoder.getFrameCount(); final int ntimes = mGifDecoder.getLoopCount(); int repetitionCounter = 0; do { for (int i = 0; i < n; i++) { mTmpBitmap = mGifDecoder.getFrame(i); int t = mGifDecoder.getDelay(i); mHandler.post(mUpdateResults); try { Thread.sleep(t); } catch (InterruptedException e) { e.printStackTrace(); } } if (ntimes != 0) { repetitionCounter++; } } while (mIsPlayingGif && (repetitionCounter <= ntimes)); }