1

I'm using Bitmap.compres(...), but I have to decode a bunch of bitmaps for that using BitmapFactory which takes a lot of time. I want to skip that decoding, if it is possible, in any way that I can make it faster. Is there a way of doing that and how?

for (int i = 0; i < inAssets.length; i++) {
                try {
                    inAssetsFolder = assetManager.list("");
                    toWrite = new File(pathToFile);
                    toWrite.mkdir();
                    for (int j = 0; j < inAssetsFolder.length; j++) {
                        inputStream = assetManager.open(inAssetsFolder[j]);
                        bmp = BitmapFactory.decodeStream(inputStream);
                        image = new File(toWrite.getAbsolutePath(),inAssetsFolder[j]);
                        fileOutputStream = new FileOutputStream(image);
                        bmp.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
                        fileOutputStream.flush();
                        fileOutputStream.close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
            }
        }
  • Past subject, but if the only issue is that the process is halted for unpleasantly long, then processing the images on a separate thread might be a solution. – Niilo Keinänen Jun 26 '19 at 12:15
  • 1
    @NiiloKeinänen That was not the solution i was looking for, but, i found the one that can suit my needs. https://stackoverflow.com/a/4530294/11690941 This answer does exactly what i need. Faster. Like 5x faster. – Marko Miljkovic Jun 26 '19 at 12:38
  • Ahh, of course, you're just copying the files - my bad, I didn't understand what you needed. – Niilo Keinänen Jun 26 '19 at 12:45

0 Answers0