The Matrix tool class is used to process special effects on images.
Matrix is a Matrix tool class that does not transform graphs and can be used with other APIs.
Obtain the Matrix object. You can create it directly and obtain it from other encapsulated Matrix classes. Transformation encapsulates the Matrix object.
You can call the Matrix object method to translate, zoom, rotate, and tilt a graphic image.
You need to apply the transformation performed by the Program on the Matrix to the specified image or component.
The following is an example of how to use a Matrix, using buttons to control Bitmap Skew and scaling.
Class MyView extends View {/** source map */private Bitmap bitmap;/** Matrix object */private Matrix matrix = new Matrix (); /** skew */public float ox = 0.0f;/** Zoom */public float scale = 1.0f;/** source image size */private int width, height; /** zoom or tilt */private boolean isScale = false; public MyView (Context context, AttributeSet attrs) {super (context, attrs ); // obtain bitmap = (BitmapDrawable) this. getResources (). getDrawable (R. drawable. ic_launcher )). getBitmap (); width = bitmap. getWidth (); height = bitmap. getHeight (); // key control, first obtain the focus this. setFocusable (true) ;}@ SuppressLint ("DrawAllocation") @ Overrideprotected void onDraw (Canvas canvas) {super. onDraw (canvas); // resets the Matrix, restores it to the source image when it is skewed, and then scales the matrix. reset (); if (isScale) {// x/y axis yoy zoom in and out matrix. setScale (scale, scale);} else {matrix. setSkew (ox, ox);} // obtain the new map Bitmap B = Bitmap. createBitmap (bitmap, 0, 0, width, height, matrix, true); // applies the transformation performed by the Program on the Matrix to the canvas on the specified image or component. drawBitmap (B, matrix, null) ;}@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent. KEYCODE_DPAD_LEFT: // tilt isScale = false; ox + = 0.1; // refresh the interface. The view class also uses this method postInvalidate (); break; case KeyEvent. KEYCODE_DPAD_RIGHT: // skewed isScale = false; ox-= 0.1; postInvalidate (); break; case KeyEvent. KEYCODE_DPAD_UP: // enlarge isScale = true; if (scale <2.0) {scale + = 0.1;} postInvalidate (); break; case KeyEvent. KEYCODE_DPAD_DOWN: // reduce isScale = true; if (scale> 0.5) {scale-= 0.1;} postInvalidate (); break; default: break;} return super. onKeyDown (keyCode, event );}}