From 820ef1e4cddc152f97bf6b60411a29f2ac5279af Mon Sep 17 00:00:00 2001 From: Lucaskyy Date: Sun, 24 Jul 2022 18:17:36 +0200 Subject: [PATCH] fix: you could make a hollywood movie out of all the hours I spent debugging and eventually after giving up found the solution on this beautiful day. Can you believe it? --- .../res/decoder/Res9patchStreamDecoder.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java index 033de3f3..9b6de4a1 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java @@ -263,8 +263,12 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length); int width = bm.getWidth(), height = bm.getHeight(); - Bitmap outImg = Bitmap.createBitmap(width + 2, height + 2, Bitmap.Config.ARGB_8888); - drawImage(outImg, bm); + Bitmap outImg = Bitmap.createBitmap(width + 2, height + 2, bm.getConfig()); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + outImg.setPixel(x + 1, y + 1, bm.getPixel(x, y)); + } + } NinePatch np = getNinePatch(data); drawHLineA(outImg, height + 1, np.padLeft + 1, width - np.padRight); @@ -317,13 +321,8 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { } outImg.compress(Bitmap.CompressFormat.PNG, 100, output); - } - - private void drawImage(Bitmap self, Bitmap toDraw) { - Canvas canvas = new Canvas(self); - Matrix matrix = new Matrix(); - matrix.mapPoints(new float[] { 1f, 1f, self.getWidth(), self.getHeight() }); - canvas.drawBitmap(toDraw, matrix, null); + bm.recycle(); + outImg.recycle(); } } }