美文网首页
安卓之 (解决方法)怎么把一个图像透明化

安卓之 (解决方法)怎么把一个图像透明化

作者: 毕利弗 | 来源:发表于2016-09-05 22:37 被阅读0次

    //第一种透明方式,设置bitmap时,就把它透明化,用一个数组,把每个像素点都设置为透明

    int[] pix = new int[tempBitmap.getWidth()* tempBitmap.getHeight()];

    for (int y = 0; y < tempBitmap.getHeight(); y++)

    for (int x = 0; x < tempBitmap.getWidth(); x++) {

    int index = y * tempBitmap.getWidth() + x;

    int r = ((pix[index] >> 16) & 0xff) | 0xff;

    int g = ((pix[index] >> 8) & 0xff) | 0xff;

    int b = (pix[index] & 0xff) | 0xff;

    pix[index] = 0xff000000 | (r << 16) | (g << 8) | b;

    // pix[index] = 0xff000000;

    }

    tempBitmap.setPixels(pix, 0, tempBitmap.getWidth(), 0, 0,

    tempBitmap.getWidth(), tempBitmap.getHeight());

    //第二种透明方式,直接在显示的时候.setAlpha(0)透明化

    imageView.setAlpha(0);

    //第三种.直接bitmap的eraseColor方法

    b.eraseColor(Color.TRANSPARENT);//用其他颜色填充,这比写矩阵要轻松不少

    相关文章

      网友评论

          本文标题:安卓之 (解决方法)怎么把一个图像透明化

          本文链接:https://www.haomeiwen.com/subject/urxdettx.html