Matrix:simple usage is to use its setxx () method directlyand advanced to understand that he is to understand a linear rectangleLet's begin by understanding the linear rectangle: (Don't take offense at drawing a rough picture)
Analysis:
Then there's a group of Mrersp_0 Mrersp_1.
I'll let you know.
such as: Choose 90 degrees that 90 degrees, put it in a corner.
Float [] x={1.0f,0.0f,0.0f,0.0f,-1.0f,0.0f,0.0f,0.0f,0.0f};
Matrix matrix=new Matrix ();
Matrix.setvalues (f);
There is also a simple point:
Matrix.setrotate (90);
If you want to revolve around which point:
Matrix.setrotate (90,x,y);
Matrix.setrotate (90,0,0);
or: Float [] x={1.0f,0.0f,0.0f,0.0f,-1.0f,0.0f,0.0f,0.0f,0.0f};
and around 100,100 can do this: the following:
Float [] x={
1.0f,0.0f,100.0f,
0.0f,-1.0f,100.0f,
0.0F,0.0F,0.0F};
Now you know what Mrersp_0 mrersp_1 is, right?
In the final analysis, this is the diagram, which focuses on a B d e and then applies the formula:
X=ax1+by1;
Y=dx1+ey1;
such as: y=-x;
What's the condition? Ask yourself a b d e how to set it the other way
Symmetric:
Instance:
Sharpen effect
public static Bitmap Tosharp (Bitmap bit)
{
Long start =system.currenttimemillis ();
Laplace matrix
int[] Laplacian = new int[] {-1,-1,-1,-1, 9,-1,-1,-1,-1};
int width = bit.getwidth ();
int height = bit.getheight ();
Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
int PIXR = 0;
int pixg = 0;
int PIXB = 0;
int pixcolor = 0;
int NEWR = 0;
int NEWG = 0;
int newb = 0;
int idx = 0;
float alpha = 0.3F;
int[] pixels = new int[width * height];
Bit.getpixels (pixels, 0, width, 0, 0, width, height);
for (int i = 1, length = height-1; i < length; i++)
{
for (int k = 1, len = width-1; k < Len; k++)
{
IDX = 0;
for (int m =-1; M <= 1; m++)
{
for (int n =-1; n <= 1; n++)
{
Pixcolor = pixels[(i + N) * width + k + m];
PIXR = Color.Red (Pixcolor);
Pixg = Color.green (Pixcolor);
PIXB = Color.Blue (Pixcolor);
NEWR = newr + (int) (PIXR * LAPLACIAN[IDX] * alpha);
NEWG = NEWG + (int) (PIXG * LAPLACIAN[IDX] * alpha);
Newb = newb + (int) (PIXB * LAPLACIAN[IDX] * alpha);
idx++;
}
}
NEWR = Math.min (255, Math.max (0, NEWR));
NEWG = Math.min (255, Math.max (0, NEWG));
Newb = Math.min (255, Math.max (0, newb));
Pixels[i * width + K] = Color.argb (255, NEWR, NEWG, newb);
NEWR = 0;
NEWG = 0;
newb = 0;
}
}
Bitmap.setpixels (pixels, 0, width, 0, 0, width, height);
Long end = System.currenttimemillis ();
LOG.D ("may", "used Time=" + (End-start));
return bitmap;
}
Rotate 90 degrees
public static Bitmap toninety (Bitmap Bitmap) {
int W=bitmap.getwidth ();
int H=bitmap.getheight ();
Float fw= ((float) 100/w);
Float fh= ((float) 100/h);
Canvas canvas=new canvas (bitmap);
Matrix matrix=new Matrix ();
Paint paint=new paint ();
Paint.setcolor (color.red);
Easy for everyone to see I write the array like this:
Final float jingxiang[]={
0.0f,1.0f,0.0f,
-1.0f,0.0f,0.0f,
0.0F,0.0F,1.0F};
Matrix.setvalues (Jingxiang);
Matrix.setrotate (90);
Matrix.postscale (FW, FH);
Canvas.drawbitmap (bitmap, matrix, paint);
Bitmap Newbitmap = Bitmap.createbitmap (Bitmap, 0, 0, w,h, Matrix, True);
return newbitmap;
}
Here's a key point: Not every CreateBitmap () method can achieve what you want, different parameters effect is not the same, I think in the final analysis of which true affects everything
But some effects without the CreateBitmap () method with the true parameter
such as black and white photo effects:
Turn the picture into black and white
public static Bitmap Tograyscale (Bitmap bmporiginal) {
int width, height;
Height = bmporiginal.getheight ();
width = Bmporiginal.getwidth ();
Bitmap Bmpgrayscale = bitmap.createbitmap (width, height,
Bitmap.Config.RGB_565);
Canvas c = new canvas (Bmpgrayscale);
Paint paint = new paint ();
ColorMatrix cm = new ColorMatrix ();
Cm.setsaturation (0);
Colormatrixcolorfilter f = new colormatrixcolorfilter (cm);
Paint.setcolorfilter (f);
C.drawbitmap (bmporiginal, 0, 0, paint);
return bmpgrayscale;
}
There are pictures of the changes and so on how to calculate how to do it ah
Next Introduction
ColorMatrix
You can think of that color coordinate as a hexahedral. Each face is a mixed color gradient effect
This ColorMatrix a day when I made a mistake. It's a waste of time, but I know more.
Same principle as matrix.
Just the array becomes RGBA
The so-called Red Green Blue Alpha
Usually:
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
This is the normal effect.
Now you can set your own effect according to the parameters.
Simple example:
public static Bitmap What (Bitmap Bitmap) {
int W=bitmap.getwidth ();
int H=bitmap.getheight ();
Bitmap result = Bitmap.createbitmap (W, H,
Bitmap.Config.RGB_565);
Canvas c = new canvas (Bmpgrayscale);
Paint paint = new paint ();
ColorMatrix cm = new ColorMatrix ();
Cm.set (New float[]{
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
});
Colormatrixcolorfilter f = new colormatrixcolorfilter (cm);
Paint.setcolorfilter (f);
C.drawbitmap (bitmap, 0, 0, paint);
return result;
}
There is a very interesting is the black and white effect introduced there
public static Bitmap Tograyscale (Bitmap bmporiginal) {
int width, height;
Height = bmporiginal.getheight ();
width = Bmporiginal.getwidth ();
Bitmap Bmpgrayscale = bitmap.createbitmap (width, height,
Bitmap.Config.RGB_565);
Canvas c = new canvas (Bmpgrayscale);
Paint paint = new paint ();
ColorMatrix cm = new ColorMatrix ();
Cm.setsaturation (0);
Colormatrixcolorfilter f = new colormatrixcolorfilter (cm);
Paint.setcolorfilter (f);
C.drawbitmap (bmporiginal, 0, 0, paint);
return bmpgrayscale;
} principle: To draw something on somethingcm.setsaturation (0); it has different effects depending on the parameters.For more study please see ANDROIDAPIactually studied this android = = studied java== Learning C #
There's something like that, huh?
Matrix and ColorMatrix