安卓:图片反色

 https://www.2cto.com/kf/201611/567911.html

int w = bitmap0.getWidth();
int h = bitmap0.getHeight();
int[] pixels = new int[w * h];
bitmap0.getPixels(pixels, 0, w, 0, 0, w, h);
for (int i=0; i<w*h; i++) {
    int color = pixels[i];
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);
    r = 255 - r;
    g = 255 - g;
    b = 255 - b;
    pixels[i] = Color.argb(a, r, g, b);
}
//直接修改bitmap崩溃
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
bitmap0 = bitmap;
imageView.setImageBitmap(bitmap0);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值