之前用到ColorMatrixColorFilter,其中除了传入一个五阶矩阵外,还可以使用ColorMatrix,调用其成员函数 /** * Set this colormatrix colorMatrix = new ColorMatrix(); //和颜色增强效果相同 colorMatrix.setScale(1.2f, 1.2f, 1.2f, that the resulting colormatrix has the same effect * as applying matB and then applying matA *
* It is legal for either matA or matB to be the same colormatrix as this. *
*/ public void setConcat(ColorMatrix matA, ColorMatrix matB) { float[](original.Width, original.Height); Graphics g = Graphics.FromImage(newBmp); ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new }); ImageAttributes img = new ImageAttributes(); img.SetColorMatrix(colorMatrix (original.Width, original.Height); Graphics g = Graphics.FromImage(newBmp); ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new
matrix = new ColorMatrix(new float[]{ 0.213f, 0.715f, 0.072f, 0, 0, matrix = new ColorMatrix(new float[]{ 0.213f, 0.715f, 0.072f, 0, 0, matrix = new ColorMatrix(new float[]{ 1, 0, 0, 0, 30, 0, 1, 0, matrix = new ColorMatrix(new float[]{ 1/2f, 1/2f, 1/2f, 0, 0, 1/ matrix = new ColorMatrix(new float[]{ 1.3f, 0, 0, 0, 0, 0, 1.3f
colorMatrix = new ColorMatrix(); colorMatrix.set(mColorMatrix);//将一维数组设置到ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.set(mColorMatrix);//将一维数组设置到ColorMatrix 取值为0表示完全无色彩,即灰度图像(黑白图像);取值为1时,表示色彩不变动;当取值大于1时,显示色彩过度饱和 如下: ColorMatrix saturationMatrix = new ColorMatrix 如下: ColorMatrix lumMatrix = new ColorMatrix(); lumMatrix.setScale(lum,lum,lum,1); 同样贴出修改亮度值的源码,当亮度为 0 saturationMatrix.setSaturation(saturation); ColorMatrix lumMatrix = new ColorMatrix();
可以在BaseActivity的onCreate方法中,使用ColorMatrix设置灰度 @Override protected void onCreate(@Nullable Bundle super.onCreate(savedInstanceState); //方案一 Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0);//灰度效果 paint.setColorFilter(new ColorMatrixColorFilter cm = new ColorMatrix(); cm.setSaturation(0); mPaint.setColorFilter(new ColorMatrixColorFilter GrayManager { private static GrayManager mInstance; private Paint mGrayPaint; private ColorMatrix
, 600 +bitmap.getWidth() / 2, 100+bitmap.getHeight() / 2); //将alpha值变为原来的一半 float[] colorMatrix //平移运算---将red通道加上100 float[] colorMatrix = new float[]{ 1,0,0,0,100, // 反相效果--底片效果 float[] colorMatrix = new float[]{ -1,0,0,0,255, // 复古效果 float[] colorMatrix = new float[]{ 1/2f,1/2f,1/2f,0,0, // 颜色通道过滤 float[] colorMatrix = new float[]{ 1,0,0,0,0, 0,0,0,0,0
colorMatrix = new ColorMatrix(matrix); mRedPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix colorMatrix2 = new ColorMatrix(matrix2); mRedPaint.setColorFilter(new ColorMatrixColorFilter (colorMatrix2)); canvas.drawBitmap(mainBitmap, 0, 0, mRedPaint); canvas.translate(350 colorMatrix3 = new ColorMatrix(matrix3); mRedPaint.setColorFilter(new ColorMatrixColorFilter colorMatrix4 = new ColorMatrix(matrix4); mRedPaint.setColorFilter(new ColorMatrixColorFilter
</param> /// <returns>The <see cref="<em>ColorMatrix</em>"/>. </param> /// <returns>The <see cref="<em>ColorMatrix</em>"/>. </param> /// <returns>The <see cref="<em>ColorMatrix</em>"/>. </param> /// <returns>The <see cref="<em>ColorMatrix</em>"/>. </param> public static void ApplyMatrix(Image image, ColorMatrix colorMatrix) { using var graphics
( varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp mat4 colorMatrix textureColor = texture2D(inputImageTexture, textureCoordinate); lowp vec4 outputColor = textureColor * colorMatrix SHADER_STRING ( varying vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform mat4 colorMatrix textureColor = texture2D(inputImageTexture, textureCoordinate); vec4 outputColor = textureColor * colorMatrix
颜色矩阵ColorMatrix 图像处理其实是一门很深奥的学科,所幸Android提供了颜色矩阵ColorMatrix类,可实现很多简单的特效,以灰阶效果为例子: Bitmap grayBitmap = originBitmap.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(grayBitmap); Paint paint = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); // 设置饱和度为0,实现了灰阶效果 colorMatrix.setSaturation(0); ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix); paint.setColorFilter(colorMatrixColorFilter
Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0);//灰度效果 paint.setColorFilter
0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements); imgAttributes.SetColorMatrix 0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix 0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix 0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix
0,0,0,(float)opcity / 100,0}, new float[]{ 0,0,0,0,1} }; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); ImageAttributes imageAtt = new ImageAttributes(); imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); return imageAtt
new float[]{0,0,0,alpha/255f,0}, new float[]{0,0,0,0,1} }; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); ImageAttributes imageAtt = new ImageAttributes (); imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)
model.Transparency, 0}, //注意:0.0f为完全透明,1.0f为完全不透明 new float[] {0, 0, 0, 0, 1}}; ColorMatrix colorMatrix = new ColorMatrix(ptsArray); //新建一个Image属性 ImageAttributes imageAttributes = new ImageAttributes(); //将颜色矩阵添加到属性 imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default
另外,除了用于关闭硬件加速和辅助属性动画这两项功能外,Layer 还可以用于给 View 增加一些绘制效果,例如设置一个 ColorMatrixColorFilter 来让 View 变成黑白的: ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0); Paint paint = new Paint(); paint.setColorFilter (new ColorMatrixColorFilter(colorMatrix)); view.setLayerType(LAYER_TYPE_HARDWARE, paint); 另外,由于设置了 View
android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorMatrix bitmap.getHeight(), bitmap.getConfig()); canvas = new Canvas(updateBitmap); paint = new Paint(); final ColorMatrix cm = new ColorMatrix(); paint.setColorFilter(new ColorMatrixColorFilter(cm)); paint.setColor(Color.BLACK
,surfaceView绘制的背景是从作为背景的ImageVIew截取的图片,会和背景颜色不一样的,只能从背景ImageView入手,还真的有改变亮度的办法,不仅可以改变亮度,还可以改变色相和饱和度 ColorMatrix colorMatrix = new ColorMatrix(); //改变图片亮度 colorMatrix.setScale(0.5f,0.5f,0.5f,1); ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); iv_bg.setColorFilter(colorFilter); 改变了亮度后对动态获取颜色会有影响
float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix
new float[]{1, 1, 1, 1, 0}, new float[]{0, 0, 0, 0, 1} }; ColorMatrix cmt=new ColorMatrix(mm2); ta.SetColorMatrix(cmt); /* //如果确知图像里仅有纯黑白二色,也可用ColorMap来反相,它可逐色改变 ColorMap