Matrix学习
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学习的更多相关文章
- Matrix学习——基础知识
以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,前段时间在使用GDI+的时候再次学习如何使用矩阵来变化图像,看了之后在这里总结说明. 首先大家看看下面这个3 x 3的矩阵,这个矩阵被分割成4部 ...
- Android Matrix类以及ColorMatri
引自:http://www.chinabaike.com/t/37396/2014/0624/2556217.html Android Matrix类以及ColorMatrix类详解 最近在系统学习了 ...
- Android Matrix理论与应用详解
转:http://zensheno.blog.51cto.com/2712776/513652 Matrix学习——基础知识 以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,前段时间在使用GD ...
- android.graphics包中的一些类的使用
游戏编程相关参考 Matrix学习系列: http://www.moandroid.com/?p=1781 Android画图学习总结系列: http://www.moandroid.com/?p=7 ...
- OpenGL.Tutorial16_ShadowMapping
1. 2. In Tutorial 15 we learnt how to create lightmaps, which encompasses(包含) static lighting. While ...
- A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- 深度学习课程笔记(十二) Matrix Capsule
深度学习课程笔记(十二) Matrix Capsule with EM Routing 2018-02-02 21:21:09 Paper: https://openreview.net/pdf ...
- 矩阵树定理(Matrix Tree)学习笔记
如果不谈证明,稍微有点线代基础的人都可以在两分钟内学完所有相关内容.. 行列式随便找本线代书看一下基本性质就好了. 学习资源: https://www.cnblogs.com/candy99/p/64 ...
随机推荐
- java - day013 - 流, FileInputStream, BufferedInputStream,
流 Stream 把数据的读写,抽象成数据在管道中流动. 流是单向的 输入流, 只能用来读取数据 输出流, 只能用来输出数据 流只能顺序读写数据 流只能一次性从头到尾读写数据 流动过的数据,不能反复流 ...
- C++——异常处理
前言 大型和十分复杂的程序往往会产生一些很难查找的甚至是无法避免的运行时错误.当发生运行时错误时,不能简单地结束程序运行,而是退回到任务的起点,指出错误,并由用户决定下一步工作.面向对象的异常处理(e ...
- Google的三大马车
Google的三大马车Google fs + Map Reduce + Big Table 开源Java实现HDFS Hadoop Hbase 云盘实现用廉价的服务器提供与万级的数据库存储①廉价的服务 ...
- tensorflow与numpy的版本兼容性问题
在Python交互式窗口导入tensorflow出现了下面的错误: root@ubuntu:~# python3 Python 3.6.8 (default, Oct 7 2019, 12:59:55 ...
- osi七层网络模型(一)
在网络中OSI分为七层网络模型,怎么理解七层模型呢?简单理解我们的手机都有手机壳.屏幕.摄像头.电池.芯片等很多原件,每个原件都是由不同的 厂家生产,最终组装成了一部功能完整的手机,同样,在网络中,也 ...
- linux网络编程之posix条件变量
今天来学习posix的最后一个相关知识----条件变量,言归正传. 下面用一个图来进一步描述条件变量的作用: 为什么呢? 这实际上可以解决生产者与消费者问题,而且对于缓冲区是无界的是一种比较理解的解决 ...
- AJAX学习笔记——跨域
跨域 一个域名地址的组成 http:// www abc.com : 8080 / scripts/jquery.js 协议 子域名 主域名 端口号 请求资源地址 端口号:一般来说域名端口号是80,如 ...
- npm的安装,升级与卸载
npm查询版本 npm -v npm安装模块 [npm install xxx]利用 npm 安装xxx模块到当前命令行所在目录: [npm install -g xxx]利用npm安装全局模块xxx ...
- pycharm鼠标更改字体大小
Pycharm快捷键设置(鼠标滚动控制字体大小) 一.pycharm字体放大的设置 File -> setting -> Keymap ->在搜寻框中输入:increase -> ...
- MySQL数据库卸载有残留, windows10 sc delete 拒绝访问 失败5
sc delete 拒绝访问,原因是当前用户的权限不足,需要做的是在注册表 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\P ...