最近在做图片相关的应用,所以就各方积累到一些常用的操作,一般来说会有多种方式来实现这一功能,比如

  1. 采用色度变换
  2. 采用ColorMatrix颜色矩阵
  3. 采用对像素点的直接操作
    等等,今天就复习一下第一种方式吧,虽然比较单一,得到的结果类型也比较少。

相比较于常见的图片风格变换,一般我们就是换个色彩度,饱和度,亮度等等,这里也恰恰是这个方式
编码思路:

  • 抽象出图片操作工具类
  • 创建一个用于操作的Bitmap对象
  • 使用画布Canvas,画笔Paint
  • 调色处理,参数控制
  • 画出Bitmap并返回
  • 被相关方法调用,得到结果

下面直接上代码吧
首先是布局

<LinearLayout 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"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:orientation="vertical"tools:context=".MainActivity" ><ImageView android:id="@+id/imageview"android:layout_width="match_parent"android:layout_height="320dp"/><LinearLayout android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextView android:text="色    度"android:textSize="18dp"android:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"/><SeekBar android:id="@+id/hueBar"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="5"/></LinearLayout><LinearLayout android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextView android:text="饱和度"android:textSize="18dp"android:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"/><SeekBar android:id="@+id/saturationBar"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="5"/></LinearLayout><LinearLayout android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextView android:text="亮    度"android:textSize="18dp"android:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"/><SeekBar android:id="@+id/lumBar"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="5"/></LinearLayout></LinearLayout>

接下来是工具操作类的相关方法

public static Bitmap handleImageLikePS(Bitmap bp,float hue,float saturation,float lum){Bitmap bitmap=Bitmap.createBitmap(bp.getWidth(), bp.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 saturationMatrix=new ColorMatrix();saturationMatrix.setSaturation(saturation);ColorMatrix lumMatrix=new ColorMatrix();lumMatrix.setScale(lum,lum,lum,1);ColorMatrix imageMatrix=new ColorMatrix();imageMatrix.postConcat(hueMatrix);imageMatrix.postConcat(saturationMatrix);imageMatrix.postConcat(lumMatrix);paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));canvas.drawBitmap(bp, 0, 0, paint);//此处如果换成bitmap就会仅仅调用一次,图像将不能被编辑return bitmap;}

然后是使用类

package com.example.colormatrixdemo;import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener{private Bitmap bitmap;private ImageView imageview;private SeekBar hueBar,saturationBar,lumBar;private float mHue,mSaturation ,mLum;private static int MAXVALUE=255,MIDVALUE=127;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.masuo);imageview=(ImageView) findViewById(R.id.imageview);hueBar=(SeekBar) findViewById(R.id.hueBar);saturationBar=(SeekBar) findViewById(R.id.saturationBar);lumBar=(SeekBar) findViewById(R.id.lumBar);hueBar.setOnSeekBarChangeListener(this);saturationBar.setOnSeekBarChangeListener(this);lumBar.setOnSeekBarChangeListener(this);hueBar.setMax(MAXVALUE);hueBar.setProgress(MIDVALUE);saturationBar.setMax(MAXVALUE);saturationBar.setProgress(MIDVALUE);lumBar.setMax(MAXVALUE);lumBar.setProgress(MIDVALUE);imageview.setImageBitmap(bitmap);}@Overridepublic void onProgressChanged(SeekBar seekbar, int progress, boolean arg2) {switch(seekbar.getId()){case R.id.hueBar:mHue=(progress-MIDVALUE)*1.0F/MIDVALUE*180;break;case R.id.saturationBar:mSaturation=progress*1.0F/MIDVALUE;break;case R.id.lumBar:mLum=progress*1.0F/MIDVALUE;break;}imageview.setImageBitmap(ImageTools.handleImageLikePS(bitmap, mHue, mSaturation, mLum));}@Overridepublic void onStartTrackingTouch(SeekBar arg0) {// TODO Auto-generated method stub}@Overridepublic void onStopTrackingTouch(SeekBar arg0) {// TODO Auto-generated method stub}}

然后运行程序,你就可以通过对滑动条的调节来对图像做相关的处理变换了。


注意:
在工具类的方法中最后要对传进去的参数做处理,而不是我们自己声明的bitmap,否则我们将得不到我们实时的图片效果。因为我们的bitmap仅仅是作为一个操作的对象模型,真正需要操作的是我们的bp参数。


总结:在处理图像有许多的方法,尤其是对图像用像素点的方式效果最多,可以呈现多种多样的效果。如老照片,浮雕,底片等等;而采用颜色矩阵也是一种好经典的操作方法。这些很值得我们学习,这样我们就可以是的我们的应用呈现出更加绚丽的色彩及效果咯!

Android图片色彩变幻相关推荐

  1. android点击图片变色,Android图片色彩变换实现方法

    最近在做图片相关的应用,所以就各方积累到一些常用的操作,一般来说会有多种方式来实现这一功能,比如 1.采用色度变换 2.采用ColorMatrix颜色矩阵 3.采用对像素点的直接操作 等等,今天就复习 ...

  2. android 图片拍照,Android获取图片拍照时间

    为什么写这篇文章是因为今早有个需求需要获取图片拍照时的时间进行一些处理,有些方法参数名忘记了,所以谷歌百度了一下,Android 图片 时间,Android 图片 拍照 时间,这几个关键字居然无法搜索 ...

  3. Android图片压缩尺寸和质量

    Android在处理图片时,如果不进行压缩处理,很容易就出现OOM内存溢出(OutOfMemory)问题,所以无论是第三方图片加载还是自己在处理图片时,都要进行压缩处理. Android系统中,一张图 ...

  4. 最详细的Android图片压缩攻略

    Mr.Louis的博客地址: https://blog.csdn.net/weixin_44005563 最近在研究图片压缩原理,看了大量资料,从上层尺寸压缩.质量压缩原理到下层的哈夫曼压缩,走成华大 ...

  5. 学会给视频添加渐入、色彩变幻特效,简单几步骤做创意小视频

    现在大家都在玩视频,有时候需要加工视频,给视频添加特效,添加背景图片等等,都会用到用剪辑的软件,那下面就为大家分享视频剪辑高手,提升大家制作的效率,下面就以给多个视频添加渐入.色彩变幻的特效为例,一起 ...

  6. Android图片系列-2.Android App图片压缩、裁剪分析整理

    移动端常用的图片格式有PNG和JPEG,目前ios手机和大部分安卓手机拍照生成的图片默认格式都是JPEG.我们开发APP的时候通常使用的是PNG,这可能是考虑到图片质量效果.PNG图片是无损压缩格式, ...

  7. 一款现代、高效的 Android 图片压缩框架

    本项目主要基于 Android 自带的图片压缩 API 进行实现,提供了开源压缩方案 Luban 和 Compressor 的实现,解决了单一 Fie 类型数据源的问题,并在它们的基础之上进行了功能上 ...

  8. Android 图片内存占用过大?不存在的...

    转载请注明出处:http://blog.csdn.net/hjf_huangjinfu/article/details/79281829 概述 Android 平台的内存,一直都是比较珍贵的,防止内存 ...

  9. 可能是最详细的Android图片压缩原理分析(一)—— Android图片压缩必备基础知识

    本篇文章已授权微信公众号guolin_blog(郭霖)独家发布 稀土掘金链接 前言: 最近在研究图片压缩原理,看了大量资料,从上层尺寸压缩.质量压缩原理到下层的哈夫曼压缩,走成华大道,然后去二仙桥,全 ...

最新文章

  1. JAVA窗帘_HomeControl 智能家具系统,包括灯光,窗帘的控制,设备,房间,情景模式的添加 Java Develop 240万源代码下载- www.pudn.com...
  2. 表中的数据导出为insert语句的简单方法
  3. CVE-2014-3153笔记
  4. 招聘 | 大疆算法类未来大咖招聘
  5. Docker三剑客之Compose
  6. curl模拟http发送get或post接口测试
  7. 重启tomcat 脚本
  8. 从二进制格雷码到任意进制格雷码(1)
  9. 投标是个技术活,不这样做要么苟且,要么狗带
  10. 利用PS将.jpg文件转换为.pdf文件
  11. 【论文笔记】Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising
  12. i-Refill | 张益唐:虽未实现大海捞针,但摸透了整个海底的情况
  13. 数据库顶级会议介绍:VLDB、SIGMOD、ICDE
  14. uniapp 图片模糊解决方案
  15. DS1602液晶显示学习笔记
  16. python从国内源下载安装包
  17. 2023年PMP超全报考指南,速速收藏!
  18. 82597-82-8,cyclo-(L)-Trp-(L)-Phe,cyclo(Phe-Trp)
  19. Python数据分析 | DataFrame(数据框)
  20. (C语言)数据结构算法-病毒感染检测(BF算法KMP算法)

热门文章

  1. 辗转相除法(既约分数)
  2. HTML5期末大作业:仿小米手机商城网站设计——仿小米手机商城全套(37页) 商城网购HTM5网页设计作业成品
  3. H3C防火墙RBM+VRRP 组网配置
  4. 百度引蜘蛛,秒爬秒收录测试(一)
  5. windows10系统-13-专利数据库检索及分析
  6. AXIOM解析XML 详细原理
  7. 专访微软研究院俞栋:基于深度学习的语音识别及CNTK的演进
  8. guacamole 源码_guacamole实现上传下载
  9. js 实现连续播放多条音频文件
  10. 智慧大厅综合管理平台 解决方案