koral--/android-gif-drawable · error · IllegalArgumentException

Bitmap ia too small, size must be greater than or equal to…

Error message

Bitmap ia too small, size must be greater than or equal to GIF size

What it means

checkBuffer requires the destination bitmap to be at least as large as the GIF's intrinsic width and height, because native rendering writes the full frame into it. A smaller bitmap would overflow/clip, so the library rejects it with IllegalArgumentException (message contains a typo 'ia too small').

Solutions

  1. Size the buffer from the decoder itself: Bitmap.createBitmap(decoder.getWidth(), decoder.getHeight(), ARGB_8888) or use allocate() which does this
  2. Before seeking, verify bitmap.getWidth() >= decoder.getWidth() && bitmap.getHeight() >= decoder.getHeight(), else recreate
  3. Catch IllegalArgumentException and reallocate a correctly sized bitmap, then retry

Example fix

// before
Bitmap small = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
decoder.seekToFrame(0, small);
// after
Bitmap buffer = Bitmap.createBitmap(decoder.getWidth(), decoder.getHeight(), Bitmap.Config.ARGB_8888);
decoder.seekToFrame(0, buffer);
Defensive patterns

Strategy: validation

Validate before calling

if (buffer.getWidth() < decoder.getWidth() || buffer.getHeight() < decoder.getHeight()) { buffer = Bitmap.createBitmap(decoder.getWidth(), decoder.getHeight(), Bitmap.Config.ARGB_8888); }

Type guard

Bitmap ensureBufferFits(Bitmap b, GifDecoder d) { return (b != null && b.getWidth() >= d.getWidth() && b.getHeight() >= d.getHeight()) ? b : Bitmap.createBitmap(d.getWidth(), d.getHeight(), Bitmap.Config.ARGB_8888); }

Try / catch

try { decoder.seekToTime(ms, buffer); } catch (IllegalArgumentException e) { buffer = Bitmap.createBitmap(decoder.getWidth(), decoder.getHeight(), Bitmap.Config.ARGB_8888); decoder.seekToTime(ms, buffer); }

Prevention

When it happens

Trigger: Calling seekToTime/seekToFrame on GifDecoder with a bitmap whose width or height is less than mGifInfoHandle.getWidth()/getHeight(), e.g. reusing a scaled-down thumbnail bitmap.

Common situations: Passing a downsampled bitmap to save memory without checking GIF dimensions; reusing a bitmap from a different (smaller) GIF after swapping sources; density-scaled bitmaps reported in different pixel units.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10). Data as JSON: /api/errors/b6b737fe64f0c384. Report an issue: GitHub.

Appendix: source

Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifDecoder.java:165

	 * @return true if GIF is animated (has at least 2 frames and positive duration), false otherwise
	 */
	public boolean isAnimated() {
		return mGifInfoHandle.getNumberOfFrames() > 1 && getDuration() > 0;
	}

	/**
	 * See {@link GifDrawable#recycle()}
	 */
	public void recycle() {
		mGifInfoHandle.recycle();
	}

	private void checkBuffer(final Bitmap buffer) {
		if (buffer.isRecycled()) {
			throw new IllegalArgumentException("Bitmap is recycled");
		}
		if (buffer.getWidth() < mGifInfoHandle.getWidth() || buffer.getHeight() < mGifInfoHandle.getHeight()) {
			throw new IllegalArgumentException("Bitmap ia too small, size must be greater than or equal to GIF size");
		}
		if (buffer.getConfig() != Bitmap.Config.ARGB_8888) {
			throw new IllegalArgumentException("Only Config.ARGB_8888 is supported. Current bitmap config: " + buffer.getConfig());
		}
	}
}

View on GitHub (pinned to 26ff795f78)