private void incrementFrameIndex() { index++; if (index >= decoder.getFrameCount()) { index = 0; } }
/* * creates an int-array of frame delays in the gifDecoder object */ private static int[] extractDelays(GifDecoder gifDecoder) { int n = gifDecoder.getFrameCount(); int[] delays = new int[n]; for (int i = 0; i < n; i++) { delays[i] = gifDecoder.getDelay(i); // display duration of frame in // milliseconds } return delays; }
/** Returns whether the given icon is an animated GIF. */ public static boolean isAnimated(Icon icon) { if (icon instanceof ImageIcon) { Image image = ((ImageIcon) icon).getImage(); if (image != null) { // Quick check for commonly-occurring animated GIF comment Object comment = image.getProperty("comment", null); if (String.valueOf(comment).startsWith("GifBuilder")) return true; // Check cache of already-decoded images if (decoded.containsKey(image)) { return Boolean.TRUE.equals(decoded.get(image)); } InputStream is = null; try { URL url = new URL(icon.toString()); is = url.openConnection().getInputStream(); } catch (Exception e) { e.printStackTrace(); } if (is == null) { try { // Beware: lots of hackery to obtain the image input stream // Be sure to catch security exceptions ImageProducer p = image.getSource(); // [macavity] - below rem'd lines don't compile on mac // if (p instanceof InputStreamImageSource) { // Method m = // InputStreamImageSource.class.getDeclaredMethod("getDecoder", null); // m.setAccessible(true); // ImageDecoder d = (ImageDecoder)m.invoke(p, null); // if (d instanceof GifImageDecoder) { // GifImageDecoder gd = (GifImageDecoder)d; // Field input = // ImageDecoder.class.getDeclaredField("input"); // input.setAccessible(true); // is = (InputStream)input.get(gd); // } // } } catch (Exception e) { e.printStackTrace(); } } if (is != null) { GifDecoder decoder = new GifDecoder(); decoder.read(is); boolean animated = decoder.getFrameCount() > 1; decoded.put(image, Boolean.valueOf(animated)); return animated; } } return false; } return icon instanceof AnimatedIcon; }
public void run() { mGifDecoder.complete(); int i, n = mGifDecoder.getFrameCount(), t; for (i = 1; i < n; i++) { mTmpBitmap = mGifDecoder.getFrame(i); t = mGifDecoder.getDelay(i); android.util.Log.v("GifAnimationDrawable", "===>Frame " + i + ": " + t + "]"); addFrame(new BitmapDrawable(mTmpBitmap), t); } decoded = true; mGifDecoder = null; }
/* * creates a PImage-array of gif frames in a GifDecoder object */ private static PImage[] extractFrames(GifDecoder gifDecoder) { int n = gifDecoder.getFrameCount(); PImage[] frames = new PImage[n]; for (int i = 0; i < n; i++) { BufferedImage frame = gifDecoder.getFrame(i); frames[i] = new PImage(frame.getWidth(), frame.getHeight(), ARGB); System.arraycopy( frame.getRGB(0, 0, frame.getWidth(), frame.getHeight(), null, 0, frame.getWidth()), 0, frames[i].pixels, 0, frame.getWidth() * frame.getHeight()); } return frames; }
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)); }
/** Load the images */ private void loadImages() { GifDecoder decode = new GifDecoder(); decode.read(file); int numFrames = decode.getFrameCount(); if (numFrames > 0) { images = new GreenfootImage[numFrames]; delay = new int[numFrames]; } else { images = new GreenfootImage[1]; images[0] = new GreenfootImage(1, 1); } for (int i = 0; i < numFrames; i++) { GreenfootImage image = new GreenfootImage(decode.getFrame(i).getWidth(), decode.getFrame(i).getHeight()); BufferedImage frame = image.getAwtImage(); Graphics2D g = (Graphics2D) frame.getGraphics(); g.drawImage(decode.getFrame(i), null, 0, 0); delay[i] = decode.getDelay(i); images[i] = image; } time = System.currentTimeMillis(); }
public void nextFrame() { if (decodeStatus == DECODE_STATUS_DECODED && index < decoder.getFrameCount()) { incrementFrameIndex(); invalidate(); } }
private void decrementFrameIndex() { index--; if (index < 0) { index = decoder.getFrameCount() - 1; } }