Tencent/matrix · error · RuntimeException

Unable to create scaled bitmap

Error message

Unable to create scaled bitmap

What it means

When the bitmap exceeds MAX_DIMENSION (1024), getBitmap asks the dataProvider to downsize it; if downsizeBitmap(size) reports failure the decoder cannot produce a scaled image and throws RuntimeException('Unable to create scaled bitmap').

Solutions

  1. Check that the BitmapDataProvider implementation supports downsizing for the bitmap's config (returns true)
  2. Handle the failure and decode the bitmap without scaling, or skip bitmaps over MAX_DIMENSION
  3. Use a Matrix analyzer version whose provider correctly rescales large bitmaps for the given hprof format

Example fix

// before
boolean couldDownsize = dataProvider.downsizeBitmap(size);
if (!couldDownsize) { throw new RuntimeException("Unable to create scaled bitmap"); }
// after
if (!dataProvider.downsizeBitmap(size)) {
    Log.w(TAG, "downsize failed; decoding at original size or skipping bitmap");
    return null; // degrade gracefully
}
Defensive patterns

Strategy: fallback

Validate before calling

Dimension size = dataProvider.getDimension();
if (size != null && (size.width > 1024 || size.height > 1024) && !dataProvider.downsizeBitmap(size)) { useOriginalOrSkip(); }

Type guard

null

Try / catch

try { return BitmapDecoder.getBitmap(provider); } catch (RuntimeException e) { if (e.getMessage().contains("Unable to create scaled bitmap")) { return decodeUnscaled(provider); } throw e; }

Prevention

When it happens

Trigger: A bitmap larger than 1024x1024 is decoded and the data provider fails to rescale it, typically because the in-memory bitmap pixel buffer could not be rewritten during hprof parsing.

Common situations: Very large screenshots/photos stored in leaked activities; hprof data providers that don't support downsizing for the given config; corrupted pixel-buffer data in the dump.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/a0603d1ca4be9b24. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer-cli/src/main/java/com/tencent/matrix/resource/analyzer/utils/BitmapDecoder.java:85

        if (config == null) {
            throw new RuntimeException("Unable to determine bitmap configuration");
        }

        BitmapExtractor bitmapExtractor = SUPPORTED_FORMATS.get(config);
        if (bitmapExtractor == null) {
            throw new RuntimeException("Unsupported bitmap configuration: " + config);
        }

        Dimension size = dataProvider.getDimension();
        if (size == null) {
            throw new RuntimeException("Unable to determine image dimensions.");
        }

        // if the image is rather large, then scale it down
        if (size.width > MAX_DIMENSION || size.height > MAX_DIMENSION) {
            boolean couldDownsize = dataProvider.downsizeBitmap(size);
            if (!couldDownsize) {
                throw new RuntimeException("Unable to create scaled bitmap");
            }

            size = dataProvider.getDimension();
            if (size == null) {
                throw new RuntimeException("Unable to obtained scaled bitmap's dimensions");
            }
        }

        return bitmapExtractor.getImage(size.width, size.height, dataProvider.getPixelBytes(size));
    }

    private static class ARGB8888_BitmapExtractor implements BitmapExtractor {
        @Override
        public BufferedImage getImage(int width, int height, byte[] rgba) {
            @SuppressWarnings("UndesirableClassUsage")
            BufferedImage bufferedImage = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_ARGB);

View on GitHub (pinned to 3b8293bd65)