仿造美图秀秀移动鼠标调整seekbar,调整图片的颜色

项目布局如下:

<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:orientation="vertical"
tools:context=".MainActivity" > <SeekBar
android:id="@+id/sb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" /> <SeekBar
android:id="@+id/sb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" /> <SeekBar
android:id="@+id/sb3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" /> <ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>

效果如下:

逻辑部分代码如下:

package com.wuyudong.resize;

import android.os.Bundle;
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.view.Menu;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity { private ImageView iv1;
private SeekBar sb1, sb2, sb3; private Bitmap alterBitmap;
private Canvas canvas;
private Paint paint; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); iv1 = (ImageView) findViewById(R.id.iv); // 设置第一个bitmap的图标
final Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher); // 新建一个bitmap
alterBitmap = Bitmap.createBitmap(bitmap1.getWidth(),
bitmap1.getHeight(), bitmap1.getConfig()); // 以alterBitmap为模板新建画布
canvas = new Canvas(alterBitmap);
// 新建画笔并设置属性
paint = new Paint();
paint.setColor(Color.BLACK); // 新建矩阵
final Matrix matrix = new Matrix(); // 指定颜色矩阵
final ColorMatrix cm = new ColorMatrix(); /**
* Set this colormatrix to identity:
* [ 1 0 0 0 0 - red vector
* 0 1 0 0 0 - green vector
* 0 0 1 0 0 - blue vector
* 0 0 0 1 0 ] - alpha vector
*/
paint.setColorFilter(new ColorMatrixColorFilter(cm)); paint.setAntiAlias(true); // 设置画布
canvas.drawBitmap(bitmap1, matrix, paint);
iv1.setImageBitmap(alterBitmap); sb1 = (SeekBar) findViewById(R.id.sb1);
sb2 = (SeekBar) findViewById(R.id.sb2);
sb3 = (SeekBar) findViewById(R.id.sb3); sb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[]{
progress/128.0f, 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(bitmap1, matrix, paint);
iv1.setImageBitmap(alterBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
});
sb2.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
cm.set(new float[]{
progress/128.0f, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, progress/128.0f, 0, 0,
0, 0, 0, 1, 0,
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap1, matrix, paint);
iv1.setImageBitmap(alterBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
});
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/128.0f, 0, 0,
0, 0, 0, 1, 0,
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap1, matrix, paint);
iv1.setImageBitmap(alterBitmap);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { } @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
});
} }

运行效果:

Android 图片的颜色处理的更多相关文章

  1. Android TextView背景颜色与背景图片设置

    Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景, android textview 图片,android te ...

  2. Android图片缓存之Lru算法

    前言: 上篇我们总结了Bitmap的处理,同时对比了各种处理的效率以及对内存占用大小.我们得知一个应用如果使用大量图片就会导致OOM(out of memory),那该如何处理才能近可能的降低oom发 ...

  3. Android图片缓存之Bitmap详解

    前言: 最近准备研究一下图片缓存框架,基于这个想法觉得还是先了解有关图片缓存的基础知识,今天重点学习一下Bitmap.BitmapFactory这两个类. 图片缓存相关博客地址: Android图片缓 ...

  4. android 图片占用内存与什么有关

    android 图片占用内存与什么有关 原文链接:http://blog.csdn.net/zjl5211314/article/details/7041813 在开发手机应用的时候,内存是有限的,那 ...

  5. Android5.0新特性——图片和颜色(drawable)

    图片和颜色 tint属性 tint属性一个颜色值,可以对图片做颜色渲染,我们可以给view的背景设置tint色值,给ImageView的图片设置tint色值,也可以给任意Drawable或者NineP ...

  6. Android 图片加载库Glide 实战(二),占位符,缓存,转换自签名高级实战

    http://blog.csdn.net/sk719887916/article/details/40073747 请尊重原创 : skay <Android 图片加载库Glide 实战(一), ...

  7. 如何改变Android标准键的颜色?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术,本文为大家讲解如何改变Android标准键的颜色 ...

  8. Android图片处理(Matrix,ColorMatrix) - 转载

    Android图片处理(Matrix,ColorMatrix) 转载自:http://www.cnblogs.com/leon19870907/articles/1978065.html 在编程中有时 ...

  9. Android图片加载框架最全解析(八),带你全面了解Glide 4的用法

    本篇将是我们这个Glide系列的最后一篇文章. 其实在写这个系列第一篇文章的时候,Glide就推出4.0.0的RC版了.那个时候因为我一直研究的都是Glide 3.7.0版本,再加上RC版本还不太稳定 ...

随机推荐

  1. VS2008 C++ 调用MATLAB 2009b 生成的DLL .

    转载: 刚开始学习用VC++调用matlab生成的DLL,找了网上一些资料,难以找到vs2008与MATLAB2009b版本的,按照以往版本做的总是有很多错误.经过两天努力,终于调试成功,这里将经验总 ...

  2. Ajax 学习 - 基础学习

    <AJax - Async Javascript and xml - 异步的JavaScript和XML> 一.基础认识 AJax技术的目的:实现页面无刷新数据动态更改 优点:  + 不需 ...

  3. win10 设置 计算机/此电脑/我的电脑 图标到桌面上

    桌面上右键--个性化 选择右边的 主题选项 然后点击 桌面图标设置 勾选计算机 图标 需要什么图标就勾选哪个就行了 然后点击 确定 这样就可以了

  4. 你应该知道的 RPC 原理

    作者:伯乐在线 - meituanalibaba   网址:http://blog.jobbole.com/92290/ 在校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用 ...

  5. android布局属性详解

    RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal  水平居中 android:layout_cen ...

  6. Hack语言的类型系统

    基础类型 PHP中主要的基础类型可以在Hack中进行显式类型标注.包含: bool int float string array resource <?hh namespace Hack\Use ...

  7. Yii2所提倡的配置管理方案

    无意中看到Yii2提供的高级应用模板,里面将入口文件与环境相关配置项放到独立的目录下的相应文件中.这应该算是一种比较理想的应用配置管理方案了. 以前整理过一种思路:http://www.cnblogs ...

  8. MurmurHash算法:高运算性能,低碰撞率的hash算法

    MurmurHash算法:高运算性能,低碰撞率,由Austin Appleby创建于2008年,现已应用到Hadoop.libstdc++.nginx.libmemcached等开源系统.2011年A ...

  9. objective-c UITableview 自定义滑操(原创)

    滑动删除在当前的ios版本中已经支持了,但是遇到复杂的比如,滑动后的功能有多个,并不是删除功能,那么你就得自己写,我说得没错吧.......... 其实关于滑删嘛,在以前的项目中也遇到过,当时ios还 ...

  10. 【C语言学习趣事】_32_平胸的尴尬,嫁不出去的姑娘

    为什么写这篇文章呢? 为什么要弄这么个题目呢? 首先解释为什么用这个题目.这一切都要从那天在QQ群中的讨论说起,那天在群中,一个哥们问了一个关于(void)0 的问题.然后大家说到了 (void)0和 ...