简体   繁体   English

透明图像背景问题android

[英]Transparent Image Background Issue android

Transparent Image background converts to Black Color After placing into Android Gallery. 将透明图像背景放入Android Gallery后,将转换为黑色。 If I upload transparent image from gallery then the image background shows black color 如果我从图库上传透明图像,则图像背景显示为黑色

    bitmap = eraseBG(bitmap, -1);         // use for white background
    bitmap = eraseBG(bitmap, -16777216);  // use for black background


private static Bitmap eraseBG(Bitmap src, int color) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap b = src.copy(Config.ARGB_8888, true);
    b.setHasAlpha(true);

    int[] pixels = new int[width * height];
    src.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int i = 0; i < width * height; i++) {
        if (pixels[i] == color) {
            pixels[i] = 0;
        }
    }

    b.setPixels(pixels, 0, width, 0, 0, width, height);

    return b;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM