{"record":{"id":"f58d66a2a3596572","repo":"bumptech/glide","slug":"unable-to-convert-drawable-to-a-bitmap","errorCode":null,"errorMessage":"Unable to convert {drawable} to a Bitmap","messagePattern":"Unable to convert (.+?) to a Bitmap","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/resource/bitmap/DrawableTransformation.java","lineNumber":55,"sourceCode":"    this.isRequired = isRequired;\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public Transformation<BitmapDrawable> asBitmapDrawable() {\n    return (Transformation<BitmapDrawable>) (Transformation<?>) this;\n  }\n\n  @NonNull\n  @Override\n  public Resource<Drawable> transform(\n      @NonNull Context context, @NonNull Resource<Drawable> resource, int outWidth, int outHeight) {\n    BitmapPool bitmapPool = Glide.get(context).getBitmapPool();\n    Drawable drawable = resource.get();\n    Resource<Bitmap> bitmapResourceToTransform =\n        DrawableToBitmapConverter.convert(bitmapPool, drawable, outWidth, outHeight);\n    if (bitmapResourceToTransform == null) {\n      if (isRequired) {\n        throw new IllegalArgumentException(\"Unable to convert \" + drawable + \" to a Bitmap\");\n      } else {\n        return resource;\n      }\n    }\n    Resource<Bitmap> transformedBitmapResource =\n        wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight);\n\n    if (transformedBitmapResource.equals(bitmapResourceToTransform)) {\n      transformedBitmapResource.recycle();\n      return resource;\n    } else {\n      return newDrawableResource(context, transformedBitmapResource);\n    }\n  }\n\n  // It's clearer to cast the result in a separate line from obtaining it.\n  @SuppressWarnings({\"unchecked\", \"PMD.UnnecessaryLocalBeforeReturn\"})\n  private Resource<Drawable> newDrawableResource(Context context, Resource<Bitmap> transformed) {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/DrawableTransformation.java#L37-L73","documentation":"Thrown by DrawableTransformation when DrawableToBitmapConverter.convert() returns null and the transformation is marked required (isRequired=true). The converter returns null for drawables that have no intrinsic size and cannot be rendered to a bitmap; when required, Glide refuses to silently skip the transformation.","triggerScenarios":"Applying a BitmapTransformation-based wrapper to a Drawable (e.g. asBitmap() or transform() with a Drawable source) where the drawable has intrinsic width/height of -1 (e.g. some ColorDrawable or shape-less drawables) and no concrete size is supplied.","commonSituations":"Calling .asBitmap().transform(new CenterCrop()) on a VectorDrawable or AdaptiveIconDrawable with -1 intrinsic dimensions. Loading a ColorDrawable through a bitmap pipeline without providing override dimensions.","solutions":["Supply concrete dimensions via .override(width, height) so the converter has a target size.","Construct DrawableTransformation with isRequired=false if skipping the transformation is acceptable.","Load the resource as Drawable (.asDrawable()) instead of forcing .asBitmap() when the source is shape-based.","Replace the drawable source with one that has intrinsic dimensions, or wrap it in a sized container."],"exampleFix":"// before\nGlide.with(ctx).load(colorDrawableUri).asBitmap().transform(new CenterCrop()).into(img);\n// after\nGlide.with(ctx).load(colorDrawableUri).asBitmap()\n  .override(img.getWidth(), img.getHeight())\n  .transform(new CenterCrop()).into(img);","handlingStrategy":"validation","validationCode":"// Provide explicit dimensions so DrawableToBitmapConverter has a target size.\nint w = target.getWidth() > 0 ? target.getWidth() : 1080;\nint h = target.getHeight() > 0 ? target.getHeight() : 1920;\nGlide.with(ctx).asBitmap()\n  .override(w, h)\n  .load(drawableSource)\n  .transform(new CenterCrop())\n  .into(target);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair .asBitmap() with .override() when sources may lack intrinsic size.","Construct DrawableTransformation with isRequired=false if you tolerate skipping.","Prefer .asDrawable() for shape-based drawables."],"tags":["drawable","bitmap","transformation","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}