首先也简单介绍下图像的RGBA模型,R指红色(Red),G指绿色(Green),B指蓝色(Blue)及A指透明度(Alpha),由这四种元素搭配组合成了各种各样的颜色。

处理工具类及方法:

public class ImageTools {
/**
* 对图片进行处理
* @description:
* @date 2015-8-12 下午8:45:05
*/
public static Bitmap getColorImage(Bitmap bitmap, float sx, float bhd, float ld) {// 参数分别是色相,饱和度和亮度
Bitmap bmp = bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
ColorMatrix sxMatrix = new ColorMatrix();// 设置色调
sxMatrix.setRotate(0, sx);
sxMatrix.setRotate(1, sx);
sxMatrix.setRotate(2, sx);

ColorMatrix bhdMatrix = new ColorMatrix();// 设置饱和度
bhdMatrix.setSaturation(bhd);

ColorMatrix ldMatrix = new ColorMatrix();// 设置亮度
ldMatrix.setScale(ld, ld, ld, 1);

ColorMatrix mixMatrix = new ColorMatrix();// 设置整体效果
mixMatrix.postConcat(sxMatrix);
mixMatrix.postConcat(bhdMatrix);
mixMatrix.postConcat(ldMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(mixMatrix));// 用颜色过滤器过滤

canvas.drawBitmap(bmp, 0, 0, paint);// 重新画图
return bmp;
}
}

在Activity中选择要处理的ImageView及对应的Bitmap,调用工具类中方法即可:

private ImageView colorIv;
private SeekBar sxBar, bhdBar, ldBar;
private static int MIN_COLOR = 100;
private static int MAX_COLOR = 255;
private float sx, bhd, ld;
private Bitmap bmp;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.color_main);
initViews();
}

private void initViews() {
bmp=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
colorIv = (ImageView) findViewById(R.id.color_iv);
colorIv.setImageBitmap(bmp);
sxBar = (SeekBar) findViewById(R.id.sx_seekbar);
bhdBar = (SeekBar) findViewById(R.id.bhd_seekbar);
ldBar = (SeekBar) findViewById(R.id.ld_seekbar);
sxBar.setOnSeekBarChangeListener(this);
sxBar.setMax(MAX_COLOR);// 设置最大值
sxBar.setProgress(MIN_COLOR);// 设置初始值(当前值)
bhdBar.setOnSeekBarChangeListener(this);
bhdBar.setMax(MAX_COLOR);
bhdBar.setProgress(MIN_COLOR);
ldBar.setOnSeekBarChangeListener(this);
ldBar.setMax(MAX_COLOR);
ldBar.setProgress(MIN_COLOR);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()) {
case R.id.sx_seekbar:
sx = (progress - MIN_COLOR) * 1.0f / MIN_COLOR * 180;
break;
case R.id.bhd_seekbar:
bhd = progress * 1.0f / MIN_COLOR;
break;
case R.id.ld_seekbar:
ld = progress * 1.0f / MIN_COLOR;
break;
}
colorIv.setImageBitmap(ImageTools.getColorImage(bmp, sx, bhd, ld));
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}

xml布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ImageView
        android:id="@+id/color_iv"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:layout_marginTop="15dp" />

<SeekBar
        android:id="@+id/sx_seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/color_iv"
         />

<SeekBar
        android:id="@+id/bhd_seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sx_seekbar"
        android:layout_marginTop="10dp" />

<SeekBar
        android:id="@+id/ld_seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/bhd_seekbar"
        android:layout_marginTop="10dp" />

</RelativeLayout>

Android学习笔记之-:对Android图像色调饱和度亮度处理相关推荐

  1. Android学习笔记07---查看Android虚拟机输出的错误信息与如何部署应用到自己的真实手机

    Android学习笔记07---查看Android虚拟机输出的错误信息

  2. Android学习笔记----解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题

    Android学习笔记----解决"com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 6553 ...

  3. Android学习笔记:对Android应用进行单元测试

     第一步:在AndroidManifest.xml中加入如下两段代码: [java] view plaincopyprint? <manifest xmlns:android="h ...

  4. [Android学习笔记四] 自定义Android组件之组合方式创建密码框组件

    Android中所有控件(也称组件)都继承自adnroid.view.View类,android.view.ViewGroup是View类的重要子类,绝大多书的布局类就继承自ViewGroup类. 参 ...

  5. Android学习笔记:Android基础知识点(不断更新中)

    1.Android学习笔记:OkHttp 2.Android学习笔记:更新UI的方法(UI线程和非UI线程) 3.Android学习笔记:Volley 4.Android学习笔记:Handler 5. ...

  6. Android学习笔记26:图片切换控件ImageSwitcher的使用

    在Windows操作系统中,要查看多张图片,可以通过使用"Windows照片查看器"在"上一张"和"下一张"之间切换,进行多张图片的浏览. ...

  7. android学习笔记---55_frame动画的实现,Java技术qq交流群:JavaDream:251572072

    android学习笔记---55_frame动画的实现,Java技术qq交流群:JavaDream:251572072 Java技术qq交流群:JavaDream:251572072 2013/5/1 ...

  8. Android学习笔记09:Paint及Canvas的简单应用

    2019独角兽企业重金招聘Python工程师标准>>> Android学习笔记09:Paint及Canvas的简单应用 在Android中需要通过graphics类来显示2D图形. ...

  9. Android学习笔记之在图片特效

    1.涂鸦(能清屏) HandWritingActivity.java [java] view plaincopy package xiaosi.handWriting; import android. ...

最新文章

  1. 计算机组装与维修是几级考试,计算机组装与维修期末考试试卷讲解学习.pdf
  2. 002_支持并发的内部类饿汉单例
  3. Python面向对象中反射和双下的正确用法
  4. 道理我都懂,但你到底为什么偏偏喜欢咬我??
  5. ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  6. Mac安装oracleVM VMware安装失败,解决方案
  7. Silverlight动态创建XAML对象和遍历对象
  8. python可以自学编程吗-编程学习第一步,让你20天搞定Python编程
  9. Eclipse编译项目内存溢出,修改配置
  10. 快速突破面试算法之分治算法篇
  11. python定时任务_Python定时任务工具--APScheduler
  12. Excel VBA生成SQL建表语句
  13. 关于matlab匿名函数,求导
  14. Heapsort 代码 学习笔记 阳春三月版
  15. 加一(python)
  16. Webpack经典入门
  17. 我的世界服务端大全-服务器插件等相关网站推荐
  18. Vue 微信小程序 uni-app学习系列《三》 实现 英语字典功能
  19. JAVA中的CAS算法
  20. makefile编写helloworld

热门文章

  1. mt4成交量指标是什么?如何看mt4成交量指标?
  2. 使用threejs实现VR看房效果,仿贝壳找房VR看房
  3. android studio环境配置
  4. ubuntu最小化所有窗口显示桌面快捷键
  5. vnpy入门操作1——安装
  6. 概率论与数理统计【二】随机事件与概率(2) - 常用求概率公式与例题两道
  7. eyemore发布全球首款AI视觉专用成像芯片,能否助推AI视觉产业跃迁?丨Xtecher 观察
  8. LSTM-实现写诗机器人
  9. Open /sys/bus/pci/devices/0000:01:00.0/driver/unbind failed. err 13 (Permission denied)
  10. 开机按F1才能进入系统解决方法