android 图像颜色处理 图像的亮度变换 更改图片饱和度
来源:互联网 发布:软件图标矢量图 编辑:程序博客网 时间:2024/06/03 23:42
图像颜色处理
颜色矩阵 ColorMatrix cm = newColorMatrix();
paint.setColorFilter(newColorMatrixColorFilter(cm));
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
New Red Value = 1*128 + 0*128 + 0*128+ 0*0 + 0
New Blue Value = 0*128 + 1*128 +0*128 + 0*0 + 0
New Green Value = 0*128 + 0*128 +1*128 + 0*0 + 0
New Alpha Value = 0*128 + 0*128 +0*128 + 1*0 + 0
ColorMatrix cm = newColorMatrix();
cm.set(new float[] {
2, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
});
paint.setColorFilter(newColorMatrixColorFilter(cm));
图像的亮度变换
ColorMatrix cm = newColorMatrix();
float contrast = 2;
cm.set(new float[] {
contrast, 0, 0, 0, 0,
0, contrast, 0, 0, 0,
0, 0, contrast, 0, 0,
0, 0, 0, 1, 0 });
paint.setColorFilter(newColorMatrixColorFilter(cm));
更改图片饱和度
ColorMatrix cm = newColorMatrix();
cm.setSaturation(.5f);
paint.setColorFilter(newColorMatrixColorFilter(cm));
---------------------------------------------------------------------
public class MainActivity extends Activity {
private ImageView iv_src;
private ImageView iv_dest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_src = (ImageView) findViewById(R.id.iv_src);
iv_src.setImageBitmap(BitmapFactory.decodeFile("/sdcard/tom.png"));
iv_dest = (ImageView) findViewById(R.id.iv_dest);
}
public void click(View view) {
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/tom.png");
Bitmap source = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
Matrix matrix = new Matrix();
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
2, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
});
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
Bitmap baseBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);
Canvas canvas = new Canvas(baseBitmap);
canvas.drawBitmap(bitmap, matrix, paint);
iv_dest.setImageBitmap(baseBitmap);
}
}
------------------------------------------------------
public class MainActivity extends Activity implements OnSeekBarChangeListener {
private ImageView iv;
private SeekBar sb_red;
private SeekBar sb_green;
private SeekBar sb_blue;
private SeekBar sb_brightness; //亮度
private SeekBar sb_saturation; //饱和度
private Bitmap preBitmap;
private Bitmap afterBitmap;
private Canvas canvas;
ColorMatrix matrix;
private Paint paint;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initData();
initLintener();
}
private void initData() {
this.iv = (ImageView) this.findViewById(R.id.iv);
this.sb_red = (SeekBar) this.findViewById(R.id.sb_red);
this.sb_green = (SeekBar) this.findViewById(R.id.sb_green);
this.sb_blue = (SeekBar) this.findViewById(R.id.sb_blue);
this.sb_brightness = (SeekBar) this.findViewById(R.id.sb_brightness);
this.sb_saturation = (SeekBar) this.findViewById(R.id.sb_saturation);
Options opts = new Options();
opts.inSampleSize = 2;
// 从资源文件获取一张不可修改的图片
this.preBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.after,opts );
// 创建一张可以被修改的空白图片
this.afterBitmap = Bitmap.createBitmap(
this.preBitmap.getWidth(), this.preBitmap.getHeight(),
this.preBitmap.getConfig());
// 以空白图片为模版创建一张画布
this.canvas = new Canvas(this.afterBitmap);
// 创建画笔
this.paint = new Paint();
// 创建颜色矩阵
this.matrix = new ColorMatrix();
this.canvas.drawBitmap(this.preBitmap, new Matrix(), this.paint);
this.iv.setImageBitmap(afterBitmap);
}
private void initLintener() {
this.sb_red.setOnSeekBarChangeListener(this);
this.sb_green.setOnSeekBarChangeListener(this);
this.sb_blue.setOnSeekBarChangeListener(this);
this.sb_brightness.setOnSeekBarChangeListener(this);
this.sb_saturation.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
switch (seekBar.getId()) {
case R.id.sb_red:
this.matrix.set(new float[]{
progress/128f,0,0,0,0,//红色
0,1,0,0,0,
0,0,1,0,0,
0,0,0,1,0
});
break;
case R.id.sb_green:
this.matrix.set(new float[]{
1,0,0,0,0,
0,progress/128f,0,0,0,//绿色
0,0,1,0,0,
0,0,0,1,0
});
break;
case R.id.sb_blue:
this.matrix.set(new float[]{
1,0,0,0,0,
0,1,0,0,0,
0,0,progress/128f,0,0, // 蓝色
0,0,0,1,0
});
break;
case R.id.sb_brightness:
this.matrix.set(new float[]{
progress/128f,0,0,0,0,
0,progress/128f,0,0,0,
0,0,progress/128f,0,0,
0,0,0,1,0
});
break;
case R.id.sb_saturation:
this.matrix.setSaturation(progress/128f);
break;
}
this.paint.setColorFilter(new ColorMatrixColorFilter(matrix));
this.canvas.drawBitmap(this.preBitmap, new Matrix(), this.paint);
this.iv.setImageBitmap(afterBitmap);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
整理自ppt和相应源码
- android 图像颜色处理 图像的亮度变换 更改图片饱和度
- 【Android图像处理】图像处理之-色相、饱和度、亮度调节
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- android图像处理系列之三--图片色调饱和度、色相、亮度处理 (转)
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- 初学颜色矩阵(修改图像的色调,饱和度,亮度)
- Android图像处理(一)色调、饱和度、亮度
- 图像处理中色调、亮度、饱和度的定义
- 图像处理中色调、亮度、饱和度的定义
- 图像处理中色调、亮度、饱和度的定义
- 图像处理之调整亮度与饱和度
- 图像处理------调整亮度与饱和度
- 图像处理之调整亮度与饱和度
- 图像处理之调整亮度与饱和度
- Android改变图像的饱和度、亮度和对比度
- devexpress表格gridcontrol实现分组,并根据分组计算总计及平均值
- devexpress实现单元格根据条件显示不同的样式(颜色、字体、对齐方式,大小等)
- Error 25003. Error occurred while initializing fusion
- Ingress intel api分析之一
- devexpress实现模仿Win8桌面metro风格
- android 图像颜色处理 图像的亮度变换 更改图片饱和度
- devexpress实现单元格合并以及依据条件合并单元格
- Linux中的yum
- 黑马程序员——Java基础--继承、抽象、接口
- Winfrom 提示消息框公共类
- PAT 数组元素循环右移问题 (Python)
- java实现二维码([带]logo)的绘制和解析(swetake.util.Qrcode)
- 失算问题(一)
- DevExpreess汉化使用方法及汉化包