你想做到跟美图秀秀一样可以处理自己的照片,美化自己的照片吗?其实你也可以自己做一个这样的软件,废话不多说了,直接上图,上代码了!

效果图如下:

没处理前:

处理之后:

MainActivity.java的代码如下:

package net.loonggg.test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity {
private SeekBar sb1, sb2, sb3, sb4, sb5;
private ImageView iv;
private Bitmap bitmap, updateBitmap;
private Canvas canvas;
private Paint paint; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
sb1 = (SeekBar) findViewById(R.id.sb1);
sb2 = (SeekBar) findViewById(R.id.sb2);
sb3 = (SeekBar) findViewById(R.id.sb3);
sb4 = (SeekBar) findViewById(R.id.sb4);
sb5 = (SeekBar) findViewById(R.id.sb5); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.b); updateBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
canvas = new Canvas(updateBitmap);
paint = new Paint();
final ColorMatrix cm = new ColorMatrix();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
paint.setColor(Color.BLACK);
paint.setAntiAlias(true);
final Matrix matrix = new Matrix();
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap); /**
* RGB三原色 红色值的设置
*/
sb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[] { progress / 128f, 0, 0, 0, 0,// 红色值
0, 1, 0, 0, 0,// 绿色值
0, 0, 1, 0, 0,// 蓝色值
0, 0, 0, 1, 0 // 透明度
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
}); /**
* RGB三原色 绿色值的设置
*/
sb2.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[] { 1, 0, 0, 0, 0,// 红色值
0, progress / 128f, 0, 0, 0,// 绿色值
0, 0, 1, 0, 0,// 蓝色值
0, 0, 0, 1, 0 // 透明度
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
}); /**
* RGB三原色 蓝色值的设置
*/
sb3.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[] { 1, 0, 0, 0, 0,// 红色值
0, 1, 0, 0, 0,// 绿色值
0, 0, progress / 128f, 0, 0,// 蓝色值
0, 0, 0, 1, 0 // 透明度
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
}); /**
* RGB三原色 三个值都改变为设置饱和度(亮度)
*/
sb4.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.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 // 透明度
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
}); /**
* RGB三原色 设置透明度
*/
sb5.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[] { 1, 0, 0, 0, 0,// 红色值
0, 1, 0, 0, 0,// 绿色值
0, 0, 1, 0, 0,// 蓝色值
0, 0, 0, progress / 128f, 0 // 透明度
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(updateBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
});
} }

布局文件代码如下:

<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:background="#CDCDCD"
android:orientation="vertical"
tools:context=".MainActivity" > <ImageView
android:id="@+id/iv"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="红色:"
android:textColor="#FF0000"
android:textSize="24sp" /> <SeekBar
android:id="@+id/sb1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="256"
android:progress="128" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="绿色:"
android:textColor="#00FF00"
android:textSize="24sp" /> <SeekBar
android:id="@+id/sb2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="256"
android:progress="128" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蓝色:"
android:textColor="#0000FF"
android:textSize="24sp" /> <SeekBar
android:id="@+id/sb3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="256"
android:progress="128" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="饱和度:"
android:textColor="#000000"
android:textSize="16.5sp" /> <SeekBar
android:id="@+id/sb4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="256"
android:progress="128" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="透明度:"
android:textColor="#000000"
android:textSize="16.5sp" /> <SeekBar
android:id="@+id/sb5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="256"
android:progress="128" />
</LinearLayout> </LinearLayout>

到这里就完了,看明白了吗?

转载请注明出处:http://blog.csdn.net/loongggdroid/article/details/18708911

Android学习记录(10)—Android之图片颜色处理的更多相关文章

  1. Android学习笔记进阶之在图片上涂鸦(能清屏)

    Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...

  2. Android学习记录(3)—Android中ContentProvider的基本原理学习总结

    一.ContentProvider简介        当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.虽然使用其他方法也可以对外共享数据 ...

  3. 【Android学习入门】Android studio基本设置

    1.背景设置 依次选择File->Settings-->Appearance & Behaviour->Apprearance,然后勾选 show line number. ...

  4. Android学习系列(10)--App列表之拖拽ListView(上)

     研究了很久的拖拽ListView的实现,受益良多,特此与尔共飨.      鉴于这部分内容网上的资料少而简陋,而具体的实现过程或许对大家才有帮助,为了详尽而不失真,我们一步一步分析,分成两篇文章. ...

  5. 【Android】Android 学习记录贴

    官网 教程学习笔记 Genymotion 安卓虚拟器太慢,用Genymotion(装载eclipse的插件) 利用Genymotion运行Android应用程序 1.首先,点击 来启动或者创建您要使用 ...

  6. android 学习随笔七(网络:图片及文本传输及线程关系 )

    主线程.子线程.UI的关系 简单的HTTP请求 -------------------------------------------------------- public class MainAc ...

  7. mono for android 学习记录

    C#开发Android应用实战(全 扫描 中文版) 学习记录: 拖完控件后,不要急着按F5,需要重新生成,才能自动修改 Resource.Designer.cs 文件 1. Activity 是基于a ...

  8. Android学习记录:界面设计

    本片文章将记录进行android界面开发时积累的知识 包括 activity全屏 activity跳转 button设计 逐个输入编辑框设计 d0710 合并旧文章总结更新 d0721 添加内容 == ...

  9. Android学习记录(6)—将java中的多线程下载移植到Android中(即多线程下载在Android中的使用)③

    在这一节中,我们就来讲多线程下载以及断点续传在android中怎么使用,前两节是为本节做准备的,没有看前两节的同学,最好看完前面的两篇文章再来看这篇.其实在android端的应用和java基本上是差不 ...

随机推荐

  1. class类重定义

    C++项目中如果一个头文件被多个文件包含,#include"xxx.h",将可能导致头文件里面定义的类被多次编译,解决方法是加编译指示: #pragma once //告诉编译器只 ...

  2. BZOJ 3090: Coci2009 [podjela]

    3090: Coci2009 [podjela] Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 23  Solved: 17[Submit][Statu ...

  3. 正交矩阵、正规矩阵和酉矩阵(转自Ramble Over The Cloud~)

    网址:http://blog.csdn.net/alec1987/article/details/7414450 在数学中,正规矩阵 是与自己的共轭转置交换的复系数方块矩阵,也就是说, 满足 其中 是 ...

  4. 如何查看某个用户指定时间段的ABAP开发记录

    输入用户名和想查询的时间段: 执行得到结果.双击可查看具体代码: 工具源代码: REPORT tool_dev_history. PARAMETERS: name TYPE usr02-bname O ...

  5. 少年开始学习c#编程,过路的大神请担待!

    这应该真正算开始学习编程, 安装好了 linux, 开通了博客员的博客, 同时今天也需要把sublime安好, 安装MonoDevelop Codeblocks mysql-workbench 配置好 ...

  6. Invalid MyEclipse License - Discontinuing this MyEclipse operation. 出现这个错误怎么改正?

    Invalid MyEclipse License - Discontinuing this MyEclipse operation这句话的意思是无效的许可证-停用此MyEclipse操作入门就是你的 ...

  7. 【JavaScript 封装库】Prototype 原型版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  8. C++11 新特性之 decltypekeyword

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/lr982330245/article/details/30728131 decltypekeywor ...

  9. 使用taobao cnpm 源解决npm无法安装module问题

    npm 安装nativescript时出现异常,一直停着不动.应该是源被墙了的问题可以使用淘宝仓库,执行下面的命令: alias cnpm="npm --registry=https://r ...

  10. Python 连接、操作数据库

    使用python3+pymysql 一.安装python3 a)         从网上下载安装吧 二.安装pymysql https://pypi.python.org/pypi/PyMySQL h ...