package com.loaderman.customviewdemo;

import android.app.Activity;
import android.graphics.ColorMatrix;
import android.os.Bundle;
import android.util.Log; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ColorMatrix colorMatrix1 = new ColorMatrix(new float[]{
0.1f, 0.2f, 0.3f, 0.4f, 0.5f,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
}); ColorMatrix colorMatrix2 = new ColorMatrix(new float[]{
0.11f, 0, 0, 0, 0,
0, 0.22f, 0, 0, 0,
0, 0, 0.33f, 0, 0,
0, 0, 0, 0.44f, 0,
}); printSetConcat(colorMatrix1,colorMatrix2);
// printPreConcat(colorMatrix1,colorMatrix2);
// printPostConcat(colorMatrix1,colorMatrix2); } private void printPostConcat(ColorMatrix colorMatrix1, ColorMatrix colorMatrix2){
Log.d("loaderman",printArray(colorMatrix1.getArray()));
Log.d("loaderman",printArray(colorMatrix2.getArray()));
colorMatrix2.postConcat(colorMatrix1);
Log.d("loaderman",printArray(colorMatrix2.getArray()));
} private void printPreConcat(ColorMatrix colorMatrix1,ColorMatrix colorMatrix2){
Log.d("loaderman",printArray(colorMatrix1.getArray()));
colorMatrix1.preConcat(colorMatrix2);
Log.d("loaderman",printArray(colorMatrix2.getArray()));
Log.d("loaderman",printArray(colorMatrix1.getArray()));
} private void printSetConcat(ColorMatrix colorMatrix1,ColorMatrix colorMatrix2){
ColorMatrix resultMatrix = new ColorMatrix(new float[]{
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
});
resultMatrix.setConcat(colorMatrix1,colorMatrix2); Log.d("loaderman",printArray(colorMatrix1.getArray()));
Log.d("loaderman",printArray(colorMatrix2.getArray()));
Log.d("loaderman",printArray(resultMatrix.getArray()));
} private String printArray(float[] array){
StringBuilder builder = new StringBuilder("array dump:\n");
for (int i=0;i<array.length;i++){
if (i%5==0){
builder.append("\n");
}
builder.append(array[i]+" ");
}
return builder.toString();
} }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <com.loaderman.customviewdemo.MyView
android:layout_width="match_parent"
android:layout_height="match_parent"/> </LinearLayout>
package com.loaderman.customviewdemo;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.view.View; public class MyView extends View {
private Paint mPaint = new Paint();
private Bitmap bitmap;// 位图 public MyView(Context context, AttributeSet attrs) {
super(context, attrs); mPaint.setAntiAlias(true);
// 获取位图
bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.dog);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas); // drawRect(canvas);
drawBitmap(canvas);
} private void drawRect(Canvas canvas){
mPaint.setARGB(255,200,100,100);
// 绘制原始位图
canvas.drawRect(0,0,500,600,mPaint); canvas.translate(550,0);
// 生成色彩矩阵
ColorMatrix colorMatrix = new ColorMatrix(new float[]{
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
});
mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
canvas.drawRect(0,0,500,600,mPaint);
} private void drawBitmap(Canvas canvas){
canvas.drawBitmap(bitmap, null, new Rect(0, 0, 500, 500 * bitmap.getHeight() / bitmap.getWidth()), mPaint); canvas.save();
canvas.translate(510, 0);
// 生成色彩矩阵
// ColorMatrix colorMatrix = new ColorMatrix(new float[]{
// 0.213f, 0.715f, 0.072f, 0, 0,
// 0.213f, 0.715f, 0.072f, 0, 0,
// 0.213f, 0.715f, 0.072f, 0, 0,
// 0, 0, 0, 1, 0,
// });
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setScale(1,1.3f,1,1);
mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix)); canvas.drawBitmap(bitmap, null, new Rect(0, 0, 500, 500 * bitmap.getHeight() / bitmap.getWidth()), mPaint); canvas.restore();
// canvas.translate(0,500);
// ColorMatrix colorMatrix2 = new ColorMatrix(new float[]{
// 0.3086f, 0.6094f, 0.0820f, 0, 0,
// 0.3086f, 0.6094f, 0.0820f, 0, 0,
// 0.3086f, 0.6094f, 0.0820f, 0, 0,
// 0 , 0 , 0 , 1, 0
// });
//
// mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix2));
// canvas.drawBitmap(bitmap, null, new Rect(0, 0, 500, 500 * bitmap.getHeight() / bitmap.getWidth()), mPaint);
//
// canvas.translate(510,0);
// ColorMatrix colorMatrix3 = new ColorMatrix(new float[]{
// 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0,
// 0, 0, 1, 0, 0,
// 0, 0, 0, 1, 0,
// });
// mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix3));
// canvas.drawBitmap(bitmap, null, new Rect(0, 0, 500, 500 * bitmap.getHeight() / bitmap.getWidth()), mPaint); }
}

效果图:

Matrix学习的更多相关文章

  1. Matrix学习——基础知识

    以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,前段时间在使用GDI+的时候再次学习如何使用矩阵来变化图像,看了之后在这里总结说明. 首先大家看看下面这个3 x 3的矩阵,这个矩阵被分割成4部 ...

  2. Android Matrix类以及ColorMatri

    引自:http://www.chinabaike.com/t/37396/2014/0624/2556217.html Android Matrix类以及ColorMatrix类详解 最近在系统学习了 ...

  3. Android Matrix理论与应用详解

    转:http://zensheno.blog.51cto.com/2712776/513652 Matrix学习——基础知识 以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,前段时间在使用GD ...

  4. android.graphics包中的一些类的使用

    游戏编程相关参考 Matrix学习系列: http://www.moandroid.com/?p=1781 Android画图学习总结系列: http://www.moandroid.com/?p=7 ...

  5. OpenGL.Tutorial16_ShadowMapping

    1. 2. In Tutorial 15 we learnt how to create lightmaps, which encompasses(包含) static lighting. While ...

  6. A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  7. A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  8. 深度学习课程笔记(十二) Matrix Capsule

    深度学习课程笔记(十二) Matrix Capsule with EM Routing  2018-02-02  21:21:09  Paper: https://openreview.net/pdf ...

  9. 矩阵树定理(Matrix Tree)学习笔记

    如果不谈证明,稍微有点线代基础的人都可以在两分钟内学完所有相关内容.. 行列式随便找本线代书看一下基本性质就好了. 学习资源: https://www.cnblogs.com/candy99/p/64 ...

随机推荐

  1. Linux命令——ps、pstree

    转载请注明出处:https://www.cnblogs.com/kelamoyujuzhen/p/9814883.html ps 简介 ps(processes status)是Unix / Linu ...

  2. 基于beautifulSoup进行电影网站排名的获取与格式化输出

    要求 编写代码完成以下任务: ① 将地址"http://www.cbooo.cn/year?year=2019"源代码使用任意方法保存到指定文件中(文件类型不限). ② 使用文件流 ...

  3. WebApi 接口恶意请求限制

    为了防止爬虫以及恶意请求,我们适当的为API增加一个请求限制   WebApiThrottle限流框架    WebApiThrottle支持自定义配置各种限流策略.可以根据不同场景配置多个不同的限制 ...

  4. 如何修改配置文件:CentOS下SSH端口修改

    CentOS各发行版中SSH端口默认为22,如果正式做站或其它用途,为了提高安全性就需要修改掉默认的SSH端口号,防止被有心人穷举密码.部分VPS提供商,若您的VPS服务器SSH遭受多次的暴力破解,可 ...

  5. 【经典/基础BFS+略微复杂的题意】PAT-L3-004. 肿瘤诊断

    L3-004. 肿瘤诊断 在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环.给定病灶扫描切片中标注出的疑似肿瘤区域,请你计算肿瘤的体积. 输入格式: 输入第一行给出4个正整数:M.N.L.T,其中M和N是 ...

  6. de4dot - Deobfuscator for .NET

    Features Here's a pseudo random list of the things it will do depending on what obfuscator was used ...

  7. master-worker常驻型程序代码修改哪些需要重启master或者worker

    之前在yii的项目里用redis作为消息队列,现在很多任务需要延迟需求,于是把之前redis的消息队列替换成了rabbitmq 于是使用yii的yii2-queue这个组件 但是由于提供的yii qu ...

  8. Robot Framework--接口测试环境搭建

    1.安装requests库 (robotframework-requests依赖这个request http client) 执行pip install requests 2. 安装requestLi ...

  9. MySQL5.7版本安装(压缩包形式)

    1.去官网下载 MySQL 压缩包 2.配置环境变量 3.创建配置文件my.ini (放置 mysql-5.7.28-winx64 目录下) my.ini 配置文件 编写如下内容 [client] p ...

  10. django-haystack 安装No local packages or working download links found for setuptools_scm

    在虚拟环境中安装drf-haystack时,pip报错 Liang-2:~ langying$ pip install django-haystack Collecting django-haysta ...