The problem is with the concurrency problem: since you use Palette in async mode, when you call
Palette.Builder(bitmap).generate(new Palette.PaletteAsyncListener()
your bitmap is valid, but when Palette uses a bitmap in its own asynchronous logic, the bitmap may already be invalid or invalid (due to simultaneous manipulation).
It is easy to fix this problem there: since you do not need a high-resolution image to extract key colors, just specify a low-resolution bitmap created from your original one:
if( bitmap == null || bitmap.getHeight() <= 0 || bitmap.getWidth() <= 0){ //do something }else{ //This resized bitmap is just an example: you should keep your bitmap //aspect ratio, and keep width and height < 100 Bitmap resizedBitmap = Bitmap.createScaledBitmap(myBitmap, 100, 100, false); Palette.Builder(resizedBitmap).generate(new Palette.PaletteAsyncListener() { ..... }
source share