图像的色调、饱和度、亮度调节
对于图像的色调、亮度、饱和度Android提供了ColorMatrix来供我们进行修改
●setRotate(int axis, float degrees) 设置色调
参数一(axis):颜色编号1(红),2(绿),3(蓝)
参数二(degrees):修改的值(这里为角度值0~360)
方法调用
ColorMatrix colorMatrixS=new ColorMatrix(); colorMatrixS.setRotate(0,one);//红 colorMatrixS.setRotate(1,one);//绿 colorMatrixS.setRotate(2,one);//蓝
●setSaturation(float sat) 设置饱和度
参数(sat):值为1时是原图,大于1饱和度增加,小于1时饱和度减少,值为0时图像为灰色
方法调用
colorMatrixB.setSaturation(three);
●setScale(float rScale, float gScale, float bScale, float aScale)设置亮度
参数一(rScale):红色
参数二(gScale):绿色
参数三(bScale):蓝色
参数四(aScale):透明度
各个参数的值对应调节各个颜色的亮度,0代表全黑1代表原图,一般将透明度的值固定设置为1(原图效果),通过调节三元色的值来调节亮度。
方法调用
colorMatrixL.setScale(two,two,two,1);
效果展示
完整代码
Activity
public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener{ SeekBar seekBarone,seekbartwo,seekbarthree; ImageView imageView; float one=1,two=1,three=1; private Bitmap baseBitmap,copyBitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.img); seekBarone=findViewById(R.id.one); seekbartwo=findViewById(R.id.two); seekbarthree=findViewById(R.id.three); seekBarone.setOnSeekBarChangeListener(this); seekbartwo.setOnSeekBarChangeListener(this); seekbarthree.setOnSeekBarChangeListener(this); baseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.aaa); //既然是复制一张与原图一模一样的图片那么这张复制图片的画纸的宽度和高度以及分辨率都要与原图一样,copyBitmap就为一张与原图相同尺寸分辨率的空白画纸 copyBitmap=Bitmap.createBitmap(baseBitmap.getWidth(), baseBitmap.getHeight(), baseBitmap.getConfig()); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { switch (seekBar.getId()){ case R.id.one: one=progress*1.0f/seekBar.getMax()*360; break; case R.id.two: two=progress*1.0f/(seekBar.getMax()-50); break; case R.id.three: three=progress*1.0f/(seekBar.getMax()-50); break; } Paint paint=new Paint(); Canvas canvas=new Canvas(copyBitmap); ColorMatrix colorMatrixS=new ColorMatrix(); colorMatrixS.setRotate(0,one); colorMatrixS.setRotate(1,one); colorMatrixS.setRotate(2,one); ColorMatrix colorMatrixL=new ColorMatrix(); colorMatrixL.setScale(two,two,two,1); ColorMatrix colorMatrixB=new ColorMatrix(); colorMatrixB.setSaturation(three); ColorMatrix colorMatriximg=new ColorMatrix(); // 通过postConcat()方法可以将以上效果叠加到一起 colorMatriximg.postConcat(colorMatrixB); colorMatriximg.postConcat(colorMatrixL); colorMatriximg.postConcat(colorMatrixS); ColorMatrixColorFilter colorMatrixColorFilter=new ColorMatrixColorFilter(colorMatriximg); paint.setColorFilter(colorMatrixColorFilter); canvas.drawBitmap(baseBitmap,new Matrix(),paint); imageView.setImageBitmap(copyBitmap); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }
布局代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.yuyigufen.customview.MainActivity"> <ImageView android:layout_width="match_parent" android:src="@mipmap/aaa" android:id="@+id/img" android:layout_height="200dp" /> <TextView android:layout_width="wrap_content" android:text="色调" android:layout_marginTop="20dp" android:layout_height="wrap_content" /> <android.support.v7.widget.AppCompatSeekBar android:layout_width="match_parent" android:layout_marginLeft="10dp" android:id="@+id/one" android:layout_marginRight="10dp" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:text="亮度" android:layout_marginTop="20dp" android:layout_height="wrap_content" /> <android.support.v7.widget.AppCompatSeekBar android:layout_width="match_parent" android:layout_marginLeft="10dp" android:id="@+id/two" android:progress="50" android:layout_marginRight="10dp" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:text="饱和度" android:layout_marginTop="20dp" android:layout_height="wrap_content" /> <android.support.v7.widget.AppCompatSeekBar android:layout_width="match_parent" android:layout_marginLeft="10dp" android:id="@+id/three" android:progress="50" android:layout_marginRight="10dp" android:layout_height="wrap_content" /> </LinearLayout>

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android--在非activity弹出Dialog对话框
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/80521795 需要在adapter类监听button点击事件弹出需要弹出一个系统级对话框,也就是这个对话框不论是在哪个活动,都可以弹出这个对话框。所以要设置对话框的属性为: WindowManager.LayoutParams.TYPE_SYSTEM_ALERT 需要加入权限: <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> Android6.0以上提权限,需要写代码跳转到设置界面让用户手动给“显示悬浮框”权限,跳转参考:https://blog.csdn.net/chaoyu168/article/details/80280200 简单实现: private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { s...
- 下一篇
Android XStream 解析xml数据变成bean,支持CDATA
参考 1、Android 用 XStream 将复杂xml解析为javabean 2、XStream支持CDATA标签 3、Retrofit 用Soap协议访问WebService 详解 实例 留着上一篇retrofit访问webservice后,最后到访问成功,到需要解析CDATA数据为止,继续下面的工作,先看下数据格式吧: * CDATA具体数据 <![CDATA[ <updatedata> <table> <name>table_xxx</name> <field>id, codeid, name, pid, remark, inputdate, modifydate, status, type_num</field> <values> <value>302|302|亚硝酸盐|1|检测项目|2016-08-24 10:58:51.0|null|C|null</value> ... <value>472|472|酱油氨基态氮|1|检测项目|2016-08-2...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Hadoop3单机部署,实现最简伪集群
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- Windows10,CentOS7,CentOS8安装Nodejs环境
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS8编译安装MySQL8.0.19
- CentOS关闭SELinux安全模块
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7