【Android图像处理】图像处理之-色相、饱和度、亮度调节

  在Android中提供了不同的通道对图片的色相、饱和度、亮度值进行修改,并且进行其中一个修改的时候不会影响其他的值。因此可以将三种调节的代码放到同一个方法中。

  下面是具体的代码:

	/**
	 * @param bm
	 * @param hue 色相
	 * @param saturation 饱和度
	 * @param lum 亮度
	 * @return
	 */
	public static Bitmap ImageEffect(Bitmap bm,float hue,float saturation,float lum){

		Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);

		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		
		//色相调节
		ColorMatrix hueMatrix = new ColorMatrix();
		hueMatrix.setRotate(0, hue);
		hueMatrix.setRotate(1, hue);
		hueMatrix.setRotate(2, hue);

		//饱和度调节
		ColorMatrix saturationColorMatrix = new ColorMatrix();
		saturationColorMatrix.setSaturation(saturation);

		//亮度调节
		ColorMatrix lumMatrix = new ColorMatrix();
		lumMatrix.setScale(lum, lum, lum, 1);

		ColorMatrix ImageMatrix = new ColorMatrix();
		ImageMatrix.postConcat(hueMatrix);
		ImageMatrix.postConcat(saturationColorMatrix);
		ImageMatrix.postConcat(lumMatrix);

		paint.setColorFilter(new ColorMatrixColorFilter(ImageMatrix));
		canvas.drawBitmap(bm, 0, 0, paint);

		return bitmap;
	}
  调用的时候用seekbar获取调节的参数:

方法如下:

	//调节seekbar的值
	private final class FliterClick3 implements OnSeekBarChangeListener{

		@Override
		public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
			switch (seekBar.getId()) {
			case 0://色相
				Pix[0] = (progress - MID_VALUE) * 1.0F / MID_VALUE * 180;
				ProcessingImage task1 = new ProcessingImage();
				task1.execute(0,7);
				break;
			case 1://饱和度
				Pix[1] = progress * 1.0F / MID_VALUE;
				ProcessingImage task2 = new ProcessingImage();
				task2.execute(0,7);
				break;				
			case 2://亮度
				Pix[2] = progress * 1.0F / MID_VALUE;
				ProcessingImage task3 = new ProcessingImage();
				task3.execute(0,7);
				break;
			}		
		}	

		@Override
		public void onStartTrackingTouch(SeekBar arg0) {

		}

		@Override
		public void onStopTrackingTouch(SeekBar arg0) {

		}

	}
  其中Pix是一个整型数组,用来存放seekBar的值。

  值得注意的是在实例化seekBar的时候要设置其最大值。

  调节的效果如下:

色相调节:


饱和度调节:


亮度调节:



这里我只调了几个数值,其实还可以联合调节的。

转载于:https://www.cnblogs.com/kaipingzhou/p/7589036.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值