您的位置:首页 > 移动开发 > Android开发

Android ColorMatrix 变换 饱和度 缩放

2017-12-07 19:44 176 查看

矩阵的一些操作

@Override
protected void onDraw(Canvas canvas) {
//关闭硬件加速
setLayerType(View.LAYER_TYPE_SOFTWARE,null);
//NORMAL: 内外都模糊绘制
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
//图片
Bitmap resource = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
//绘制原图
canvas.drawBitmap(resource,100,100,paint);
//设置颜色过滤器
ColorMatrix matrix = new ColorMatrix();
paint.setColorFilter(new ColorMatrixColorFilter(matrix));
canvas.drawBitmap(resource,500,100,paint);
}


常用的一些API

Colormatrix 类中的方法
/**
* 色彩缩放
*/
public void setScale(float rScale, float gScale, float bScale,float aScale) {}

/**
* 饱和度设置
* 0 == 灰色图片
* 1 == 保持不变
* >1 增加饱和度
*/
public void setSaturation(float sat) {}

/**
* 色彩旋转
* @axis 绕着那个轴旋转(0,1,2)
* <code>axis=0</code> 绕着红轴
* <code>axis=1</code> 绕着绿轴
* <code>axis=2</code> 绕着蓝轴
* @degrees   旋转的度数
*/
public void setRotate(int axis, float degrees) {}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: