您的位置:首页 > 编程语言 > Java开发

图像处理之图像rgb取平均(java)

2016-01-28 10:48 501 查看
/**
* 图像处理线程
* 获取图像的rgb平均值
*/
class myThread implements Runnable {
public void run() {
BitmapDrawable db = (BitmapDrawable) getResources().getDrawable(R.mipmap.mirror);
Bitmap bitmap = db.getBitmap();
int width = bitmap.getWidth();
int hight = bitmap.getHeight();
int[] pixs = new int[width*hight];
int sum_r = 0;
int sum_g = 0;
int sum_b = 0;
int sum_a = 0;
int cunt = 0;
bitmap.getPixels(pixs, 0, width, 0, 0, width, hight);
for (int i =0;i<width*hight;i++){
int r = Color.red(pixs[i]);
int g = Color.green(pixs[i]);
int b = Color.blue(pixs[i]);
int a = Color.alpha(pixs[i]);

//去除黑色点
if (r!=0 && g!=0 && b!=0){
sum_r+=r;
sum_g+=g;
sum_b+=b;
sum_a+=a;
cunt++;
}
}
//color数组中存放平均之后的rgb值
int[] color = new int[4];
color[0] = sum_r/cunt;
color[1] = sum_g/cunt;
color[2] = sum_b/cunt;
color[3] = sum_a/cunt;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: