图像处理库 android,Android图像处理库

使用下面的代码来对比增加了位:值的范围从1到100

public static Bitmap AdjustContrast(Bitmap original, float Value){

Value = (100.0f + Value)/100.0f;

Value *= Value;

Bitmap newBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(),original.getConfig());

int[] argb = new int[original.getWidth() * original.getHeight()];

original.getPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

for (int i = argb.length - 1; i >= 0; --i) {

int alpha = argb[i] >> 24;

int red = (argb[i] >> 16) & 0xFF;

int green = (argb[i] >> 8) & 0xFF;

int blue = argb[i] & 0xFF;

float Red = red/255.0f;

float Green = green/255.0f;

float Blue = blue/255.0f;

Red = (((Red - 0.5f) * Value) + 0.5f) * 255.0f;

Green = (((Green - 0.5f) * Value) + 0.5f) * 255.0f;

Blue = (((Blue - 0.5f) * Value) + 0.5f) * 255.0f;

int iR = (int)Red;

iR = iR > 255 ? 255 : iR;

iR = iR < 0 ? 0 : iR;

int iG = (int)Green;

iG = iG > 255 ? 255 : iG;

iG = iG < 0 ? 0 : iG;

int iB = (int)Blue;

iB = iB > 255 ? 255 : iB;

iB = iB < 0 ? 0 : iB;

int composite = (alpha << 24) | (iR << 16) | (iG << 8) | iB;

argb[i] = composite;

}

newBitmap.setPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

Store.lastBitmap = newBitmap;

return newBitmap;

}

使用此亮度效果:值应介于1到100之间

public static Bitmap makeBrightnessBitmap(Bitmap original, int brightness){

Bitmap newBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(),original.getConfig());

int[] argb = new int[original.getWidth() * original.getHeight()];

original.getPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

for (int i = argb.length - 1; i >= 0; --i) {

int alpha = argb[i] >> 24;

int red = (argb[i] >> 16) & 0xFF;

int green = (argb[i] >> 8) & 0xFF;

int blue = argb[i] & 0xFF;

int red2 = red + brightness;

if (red2>0xFF) red2 = 0xFF;

if (red2<0) red2 = 0;

int green2 = green + brightness;

if (green2>0xFF) green2 = 0xFF;

if (green2<0) green2 = 0;

int blue2 = blue + brightness;

if (blue2>0xFF) blue2 = 0xFF;

if (blue2<0) blue2 = 0;

int composite = (alpha << 24) | (red2 << 16) | (green2 << 8) | blue2;

argb[i] = composite;

}

newBitmap.setPixels(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

Store.lastBitmap = newBitmap;

return newBitmap;

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值