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. openwrt 切换overlay文件系统为根文件系统

    http://blog.chinaunix.net/uid-27057175-id-4584360 openwrt的overlayfs 通过/etc/preinit调用 /sbin/mount_roo ...

  2. Paper Reading:Deep Neural Networks for YouTube Recommendations

    论文:Deep Neural Networks for YouTube Recommendations 发表时间:2016 发表作者:(Google)Paul Covington, Jay Adams ...

  3. C#格式化信息,格式化数字、格式化日期

    一.格式化方法: 1.ToString()实例方法 使用当前文化: varname.ToString("C4"); 使用特定文化: varname.ToString("C ...

  4. Java锁--CountDownLatch

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3533887.html CountDownLatch简介 CountDownLatch是一个同步辅助类,在 ...

  5. shell 学习笔记2

    shell的常用处理:https://github.com/dylanaraps/pure-bash-bible -d作为分隔符:read xargs -t作为分隔符:sort -F作为分隔符:awk ...

  6. Spring Cloud 功能使用的层面组件(一)

    来源:赤峰seo 实际上,Spring Cloud 是一个全家桶式的技术栈,它包含了很多组件.本文先从最核心的几个组件,也就是 Eureka.Ribbon.Feign.Hystrix.Zuul 入手 ...

  7. jquery仿排列顺序,变换颜色更换class

    ps:箭头是字体图标,需要的可以去阿里字体下载,也可自己替换图片 点击之后的 代码部分 <ul class="Ep_sxxz"> <span class=&quo ...

  8. CSP-S 2019 第二轮 退役记

    Day 0 复习数论,复习网络流,复习动态DP,复习ac自动机,复习后缀自动机- Day 1 进考场,得到解压密码,跟时事热点没有什么关系. 感觉键盘有点难受,右半部分包括退格.方向键.回车都比较黏. ...

  9. perfectpixel 加载PSD图到网页中和已经写好的网页进行对比

    perfectpixel  这是火狐的插件: 用途:加载设计图,和 已经编写好的网页进行对比,看是否完美还原. 谷歌也有类似的插件,但是无法下载.

  10. 【编程语言】Kotlin之扩展函数

    简介: 平时Android开发中会使用各种各样的工具类函数,大部分工具类都是对原有对象的一种扩展,例如: public static void startActivity(Activity act, ...