{"record":{"id":"a0603d1ca4be9b24","repo":"Tencent/matrix","slug":"unable-to-create-scaled-bitmap","errorCode":null,"errorMessage":"Unable to create scaled bitmap","messagePattern":"Unable to create scaled bitmap","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer-cli/src/main/java/com/tencent/matrix/resource/analyzer/utils/BitmapDecoder.java","lineNumber":85,"sourceCode":"        if (config == null) {\n            throw new RuntimeException(\"Unable to determine bitmap configuration\");\n        }\n\n        BitmapExtractor bitmapExtractor = SUPPORTED_FORMATS.get(config);\n        if (bitmapExtractor == null) {\n            throw new RuntimeException(\"Unsupported bitmap configuration: \" + config);\n        }\n\n        Dimension size = dataProvider.getDimension();\n        if (size == null) {\n            throw new RuntimeException(\"Unable to determine image dimensions.\");\n        }\n\n        // if the image is rather large, then scale it down\n        if (size.width > MAX_DIMENSION || size.height > MAX_DIMENSION) {\n            boolean couldDownsize = dataProvider.downsizeBitmap(size);\n            if (!couldDownsize) {\n                throw new RuntimeException(\"Unable to create scaled bitmap\");\n            }\n\n            size = dataProvider.getDimension();\n            if (size == null) {\n                throw new RuntimeException(\"Unable to obtained scaled bitmap's dimensions\");\n            }\n        }\n\n        return bitmapExtractor.getImage(size.width, size.height, dataProvider.getPixelBytes(size));\n    }\n\n    private static class ARGB8888_BitmapExtractor implements BitmapExtractor {\n        @Override\n        public BufferedImage getImage(int width, int height, byte[] rgba) {\n            @SuppressWarnings(\"UndesirableClassUsage\")\n            BufferedImage bufferedImage = new BufferedImage(width, height,\n                BufferedImage.TYPE_INT_ARGB);\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer-cli/src/main/java/com/tencent/matrix/resource/analyzer/utils/BitmapDecoder.java#L67-L103","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that the BitmapDataProvider implementation supports downsizing for the bitmap's config (returns true)","Handle the failure and decode the bitmap without scaling, or skip bitmaps over MAX_DIMENSION","Use a Matrix analyzer version whose provider correctly rescales large bitmaps for the given hprof format"],"exampleFix":"// before\nboolean couldDownsize = dataProvider.downsizeBitmap(size);\nif (!couldDownsize) { throw new RuntimeException(\"Unable to create scaled bitmap\"); }\n// after\nif (!dataProvider.downsizeBitmap(size)) {\n    Log.w(TAG, \"downsize failed; decoding at original size or skipping bitmap\");\n    return null; // degrade gracefully\n}","handlingStrategy":"fallback","validationCode":"Dimension size = dataProvider.getDimension();\nif (size != null && (size.width > 1024 || size.height > 1024) && !dataProvider.downsizeBitmap(size)) { useOriginalOrSkip(); }","typeGuard":"null","tryCatchPattern":"try { return BitmapDecoder.getBitmap(provider); } catch (RuntimeException e) { if (e.getMessage().contains(\"Unable to create scaled bitmap\")) { return decodeUnscaled(provider); } throw e; }","preventionTips":["Implement downsizeBitmap() correctly in custom BitmapDataProviders","Test decoding with bitmaps larger than 1024x1024","Handle large leaked bitmaps (screenshots) with graceful skip logic"],"tags":["heap-dump","bitmap-decoding","scaling"],"backgroundTag":"unsupported-operation","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}