Skip to content

Instantly share code, notes, and snippets.

@clafferty-powa
Created January 26, 2015 16:50
Show Gist options
  • Save clafferty-powa/d92890f6d5858730e627 to your computer and use it in GitHub Desktop.
Save clafferty-powa/d92890f6d5858730e627 to your computer and use it in GitHub Desktop.
Make all pixels with transparency black, and remove their alpha channel on Android Bitmap
// For input image where information is only stored in alpha channel over black RGB.
// Make all pixels with transparency black, and remove alpha channel.
private Bitmap AlphaToBlack(Bitmap image) {
Bitmap rgbImage = image.copy(Bitmap.Config.ARGB_8888, true);
for (int y = 0; y < rgbImage.getHeight(); y++) {
for (int x = 0; x < rgbImage.getWidth(); x++) {
int aPixel = rgbImage.getPixel(x, y);
if (rgbImage.getPixel(x, y) < 0xFF000000)
rgbImage.setPixel(x, y, 0xFF000000);
}
}
return rgbImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment