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软件——aptitude

    https://help.ubuntu.com/lts/serverguide/aptitude.html.en

  2. roles

    nginx 官方下载 [root@ansible roles]# tree yngx yngx ├── defaults ├── files │   ├── blog.conf │   ├── edu ...

  3. Mysql DELETE 不能使用别名? 是我不会用!

    今天碰到一个sql问题,就是在delete中加了别名,导致报错了:"[Err] 1064 - You have an error in your SQL syntax; ..." ...

  4. appium 使用name 定位报错 Locator Strategy 'name' is not supported for this session

    RF中使用 name定位 报错提示: Locator Strategy 'name' is not supported for this session 解决: 1. 打开本地文件 driver.js ...

  5. 泛型 System.Collections.Generic及泛型继承、运算符、结构、接口、方法、委托、事件、可空类型等

    一.定义泛型类 void Main() { //实例化泛型类时,才指定具体的类型 MyGenericClass<); Console.WriteLine(MyGeneri.InnerT1Obje ...

  6. java中使用redis --- List列表的简单应用

    1.Dos中启动server端 2.idea中启动client端 public class RedisTest01 { public static void main(String[] args){ ...

  7. C语言Ⅰ博客作业06

    这个作业属于哪个课程 C语言程序设计Ⅰ 这个作业要求在哪里 熟练掌握多分支结构,字符型数据类型和逻辑运算符 我在这个课程的目标是 https://www.cnblogs.com/tongyingjun ...

  8. stm32 HardFault_Handler调试及问题查找方法——飞思卡尔

    看到有朋友遇到Hard Fault 异常错误,特地找到一篇飞思卡尔工程师写的一片经验帖,定位Hard Fault 异常. Kinetis MCU 采用 Cortex-M4 的内核,该内核的 Fault ...

  9. HDU 6010 - Daylight Saving Time

    先算周几,再模拟 #include <bits/stdc++.h> using namespace std; int GetWeekDay(int y,int m,int d)//0为周一 ...

  10. centos svn的安装和配置

    1.安装svn yum -y install subversion 2.配置 mkdir /home/svn/admin/test mkdir /home/svn/svnrepos svnadmin ...