Artwork: effect 1: effect 2:
Effect 3: Effect 4:
View the official API, where ColorMatrix's instructions are as follows:
5X4 matrix for transforming the Color+alpha components of a Bitmap. The matrix is stored. A single array, and its
Treated as follows: [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, p, Q, R, S, T] when applied to a color [R, G, B, a], t He resulting
Color is computed as (after clamping) R ' = a*r + b*g + c*b + d*a + E; G ' = f*r + g*g + h*b + i*a + j; B ' = k*r + l*g +
M*b + n*a + o; A ' = p*r + q*g + r*b + s*a + t;
So here I simply understand:
The so-called color matrix is actually a bitmap, that this bitmap is a matrix of 5*4, this matrix involves color and transparency, according to one of the above formula, we can draw this color matrix:
A b c d E
f g H i J
K l m N o
P Q R S I
In addition to the 5*4 color matrix, we also need the image of the RGBA value, through RGBA can determine the image color rendering effect, the image of the RGBA values stored in a 5*1 color component matrix, as follows:
R
G
B
A
1
If we want to change the color of the image, it can be done by changing the color component matrix of the image, the formula for the color component matrix is as follows:
A b c d e R ar+bg+cb+da+e
f g H i j G fr+gg+hb+ja+j
* B =
K l m n o A kr+ig+mb+na+o
P Q R S i 1 pr+qg+rb+sa+i
So the first line above represents the red component, the second row represents the green component, the third row represents the blue component, and the fourth row represents transparency.
The code is as follows:
public class Mainactivity extends Activity {private Button btn_start;private ImageView img;private Bitmap bitmap;private F Loat[] Colorarray = { 1, 0, 0, 0, 0,0, 1, 0, 0,, 0, 1, 0, 0,0, 0, 0, 1, 0}, @Overrideprotected void OnCreate (Bundl E savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.image_layout); InitView ();} private void Initview () {img = (ImageView) Findviewbyid (r.id.iv_image); bitmap = ((bitmapdrawable) img.getdrawable ()). Getbitmap (); Btn_start = (Button) Findviewbyid (R.id.btn_start); Btn_start.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View v) {Bitmap BM = imagetools.toprocessimage (Bitmap,colorarray); Img.setimagebitmap (BM);}}); }}
Imagetools Tool Class:
/** * Image Effect processing * @param bmp Incoming picture * @param colorarray color Matrix value * @return */public static Bitmap toprocessimage (Bitmap b Mp,float[] colorarray) {if (bmp!=null&&colorarray!=null) {int width, height;height = Bmp.getheight (); width = Bmp.getwidth (); Bitmap BM = Bitmap.createbitmap (width, height,bitmap.config.rgb_565); Paint Mypaint = new paint (); Canvas canvas=new canvas (BM); ColorMatrix Mycolormatrix = new ColorMatrix (); Mycolormatrix.set (Colorarray); Mypaint.setcolorfilter (New Colormatrixcolorfilter (Mycolormatrix)); Canvas.drawbitmap (bmp,0,0,mypaint); return BM;} Else{return bmp;}}
Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/45193115 Emotional Control _
Learn about Android with the use of ColorMatrix for various special effects processing of pictures (32)