(Android) canvas movement and flip
Android canvas flip is a powerful tool, especially in image processing. You can easily change the origin without having to reverse the array with a bunch of linear changes.
Just like the sauce purple, at the beginning, the canvas sister overlaps with the display area brother, tacit understanding is like a person, three views are consistent, the starting point is unified in the upper left corner. The images we draw are displayed on the canvas in the display area. This is the result of drawing a progress bar on the canvas.
If you want to get a vertical bar, we will flip the canvas, first Flip 90 ° counterclockwise, get
At this time, the world of the canvas sister and brother in the display area is no longer the same coordinate system.
Their world is different. In order to make the world they see the same world, the canvas sister will move the getHeight of a display area negatively relative to its coordinate origin.
After the canvas where the widget is located is converted, we get a vertical control. Code implementation:
Protected synchronized void onDraw (Canvas canvas) {canvas. rotate (-90); canvas. translate (-getHeight (), 0); super. onDraw (canvas );}