【问题标题】:Transparent Image Background Issue android透明图像背景问题android
【发布时间】:2018-07-04 04:47:10
【问题描述】:

透明图像背景在放入 Android 图库后转换为黑色。如果我从图库上传透明图像,则图像背景显示黑色

【问题讨论】:

标签: android android-imageview android-gallery


【解决方案1】:
    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;
}

【讨论】:

  • 在添加代码之前,图像显示如下,请参阅链接ibb.co/cqPchJ 或添加代码后,图像显示如下,请参阅链接ibb.co/gwRb9y 感谢您的帮助..
  • 使用 myImage.setAlpha(0);并上传
  • OR mComponentName.setBackgroundColor(Color.parseColor("#80000000"));
猜你喜欢
  • 2010-11-22
  • 1970-01-01
  • 1970-01-01
  • 2012-02-26
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 2011-09-15
相关资源
最近更新 更多