I'm making an image editing app where the user can touch the screen and place a "sticker" over their photo.
My stickers all have green backgrounds (0, 255, 0) that I'd like to make transparent. However, the pixels don't come out as transparent, but black instead.
Here's my code to load a transparent bitmap:
private Bitmap transparentBitmap(int id)
{
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inMutable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), id, bmOptions);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = y * width + x;
if (pixels[index] == Color.GREEN)
{
pixels[index] = Color.argb(0, 0, 0, 0);
}
}
}
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
I load all the stickers in the beginning of the app, and when the user touches the screen somewhere, the graphic is copied from a static Bitmap from my Assets class:
private Bitmap getGFX(stickerTypes type)
{
switch(type)
{
case sweatDrop: return Assets.sweatDrop_GFX.copy(Config.ARGB_4444, true);
case veins: return Assets.veins_GFX.copy(Config.ARGB_4444, true);
default: return null;
}
}
So like I said, my actual stickers are not showing up with transparent background, but with black backgrounds. They're saved as .pngs.
The only explanation I can think of is that the stickers' background pixels are being set to transparent relative to the background of the activity as opposed to the background of the users' picture, but that doesn't make much sense because the background of the activity is orange, not black.