- Create a new bitmap, with the size and config of the bitmap you wish to change.
- Create a Canvas and prepare it to paint to the new bitmap.
- Paint the new bitmap with your color using the canvas object.
- Draw the old bitmap to the new bitmap through the canvas object.
- Do what you want with the new bitmap
// Create new bitmap based on the size and config of the old Bitmap newBitmap = Bitmap.createBitmap(oldBitmap.getWidth(), oldBitmap.getHeight(), oldBitmap.getConfig()); // Instantiate a canvas and prepare it to paint to the new bitmap Canvas canvas = new Canvas(newBitmap); // Paint it white (or whatever color you want) canvas.drawColor(Color.WHITE); // Draw the old bitmap ontop of the new white one canvas.drawBitmap(oldBitmap, 0, 0, null);
Thanks man! You great!
After literally scrolling through dozens of articles, this finally gets me the solution. Everyone gave me the complete code except for one very crucial part –
Bitmap newBitmap = Bitmap.createBitmap(oldBitmap.getWidth(), oldBitmap.getHeight(), oldBitmap.getConfig());
Apparently, I was overwriting the same thing. Thanks a lot for this bud!