根据RGB配色改变图片颜色

//改变图片三色值,频繁调用方法,不要用静态,静态生命周期太长,不容易销毁

public Bitmap drawBg4Bitmap(int progress,int progressR,int progressG,int progressB, Bitmap orginBitmap, int id,boolean isSuCai) {
    
    int w = orginBitmap.getWidth();
    int h = orginBitmap.getHeight();
    int bytes = orginBitmap.getByteCount();
    ByteBuffer buf = ByteBuffer.allocate(bytes);
    orginBitmap.copyPixelsToBuffer(buf);
    byte[] byteArray = buf.array();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int index = y * w + x;
            int A = convertByteToInt(byteArray[index * 4 + 3]);
            if (A > 10) {
              if(isSuCai){
                  if (isPureColor ==1) {
                      byteArray[index * 4] = (byte) progressR;
                      byteArray[index * 4 + 1] = (byte) progressG;
                      byteArray[index * 4 + 2] = (byte) progressB;
                  } else {
                      switch (id) {
                          case 0:
                              byteArray[index * 4] = (byte) progress;
                              break;
                          case 1:
                              byteArray[index * 4 + 1] = (byte) progress;
                              break;
                          case 2:
                              byteArray[index * 4 + 2] = (byte) progress;
                              break;
                          default:
                              break;

                      }
                  }
                }else {

                    switch (id) {
                        case 0:
                            byteArray[index * 4] = (byte) progress;
                            break;
                        case 1:
                            byteArray[index * 4 + 1] = (byte) progress;
                            break;
                        case 2:
                            byteArray[index * 4 + 2] = (byte) progress;
                            break;
                        default:
                            break;

                    }

                }
            }
        }
    }

    Bitmap stitchBmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    stitchBmp.copyPixelsFromBuffer(ByteBuffer.wrap(byteArray));

    return stitchBmp;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值