bumptech/glide · error · IllegalArgumentException

Cannot scale with factor: {exactScaleFactor} from: {downsamp

Error message

Cannot scale with factor: {exactScaleFactor} from: {downsampleStrategy}, source: [{sourceWidth}x{sourceHeight}], target: [{targetWidth}x{targetHeight}]

What it means

Thrown by Downsampler when DownsampleStrategy.getScaleFactor() returns a value <= 0 for the given source and target dimensions. Glide interprets a non-positive scale factor as the strategy being unable to produce a valid downsampling ratio, so decoding is aborted rather than producing a corrupt or zero-size bitmap.

Source

Thrown at library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java:549

    }

    int orientedSourceWidth = sourceWidth;
    int orientedSourceHeight = sourceHeight;
    // If we're rotating the image +-90 degrees, we need to downsample accordingly so the image
    // width is decreased to near our target's height and the image height is decreased to near
    // our target width.
    //noinspection SuspiciousNameCombination
    if (isRotationRequired(degreesToRotate)) {
      orientedSourceWidth = sourceHeight;
      orientedSourceHeight = sourceWidth;
    }

    final float exactScaleFactor =
        downsampleStrategy.getScaleFactor(
            orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight);

    if (exactScaleFactor <= 0f) {
      throw new IllegalArgumentException(
          "Cannot scale with factor: "
              + exactScaleFactor
              + " from: "
              + downsampleStrategy
              + ", source: ["
              + sourceWidth
              + "x"
              + sourceHeight
              + "]"
              + ", target: ["
              + targetWidth
              + "x"
              + targetHeight
              + "]");
    }

    SampleSizeRounding rounding =
        downsampleStrategy.getSampleSizeRounding(

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Inspect the source image: if the source reports 0x0 dimensions the file is corrupt; replace or skip it.
  2. If using a custom DownsampleStrategy, ensure getScaleFactor always returns > 0 for positive inputs (e.g. fall back to 1f).
  3. Validate image dimensions before requesting decode, or use .error()/fallback to handle corrupt sources gracefully.
  4. Switch to a built-in DownsampleStrategy (DEFAULT, CENTER_OUTSIDE) to rule out custom-strategy bugs.

Example fix

// before
public float getScaleFactor(int sw, int sh, int tw, int th) {
  return tw == 0 ? 0f : (float) tw / sw; // returns 0 when target width is 0
}
// after
public float getScaleFactor(int sw, int sh, int tw, int th) {
  if (sw <= 0 || sh <= 0) return 1f;
  return tw <= 0 ? 1f : Math.max((float) tw / sw, (float) th / sh);
}
Defensive patterns

Strategy: validation

Validate before calling

// Before decoding, verify source dimensions are positive.
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input.markSupported() ? input : new BufferedInputStream(input), null, opts);
if (opts.outWidth <= 0 || opts.outHeight <= 0) {
  // skip / fallback instead of letting Downsampler throw
}

Try / catch

try { Glide.with(ctx).load(url).into(target); }
catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Cannot scale with factor")) {
    // log corrupt image, show placeholder
  } else throw e;
}

Prevention

When it happens

Trigger: A custom DownsampleStrategy whose getScaleFactor returns 0 or a negative number (often when sourceWidth or sourceHeight is 0). Decoding an image with reported 0x0 dimensions, or a corrupted/truncated image header where the decoder reports zero source dimensions.

Common situations: Registering a custom DownsampleStrategy via .set(DownsampleStrategy.OPTION, customStrategy) that has an edge case returning 0. Loading a malformed GIF/PNG/WebP whose metadata reports 0 dimensions. DownsampleStrategy.NONE misused together with a target of 0.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/aa018dd1674529e1. Report an issue: GitHub.