Maybe some students do not understand, why should the picture reversal (not rotating OH), we are in the game development, in order to save the picture resources (space) may use to the picture inversion, for example, a character picture, facing the left, or right, if can not realize the picture inversion case, will need two pictures, the nonsense says less, See the effect on the code:
In the figure above, the actual two characters are using a picture, which is only handled for a single image.
Detailed code:
public class Imagesurfaceview extends Surfaceview implements surfaceholder.callback{public Bitmap Image_bitmap;
Public Imagesurfaceview {Super (context);
Add callback Surfaceholder Holder=this.getholder ();
Holder.addcallback (this);
Initbitmap (context);
The public void Initbitmap {resources r=context.getresources ();
Image_bitmap=bitmapfactory.decoderesource (R,r.drawable.ima); }//interface rendering public void OnDraw (Canvas Canvas) {canvas.drawbitmap (image_bitmap,0,0, NULL);//output First picture//Initialize Matrix This class is for graphics
Some effects of the tool class matrix M=new matrix ();
M.setscale ( -1,1); M.posttranslate (Image_bitmap.getwidth () *2,0); Position two picture widths to the right canvas.drawbitmap (Image_bitmap, M, paint); Output second picture} @Override public void surfacechanged (surfaceholder holder, int format, int width, int height) {} @Ov Erride public void surfacecreated (Surfaceholder holder) {Canvas canvas=holder.lockcanvas ();//Invoke the rendering interface method to render the interface OnDraw
(canvas);
Holder.unlockcanvasandpost (canvas); } @OVerride public void surfacedestroyed (Surfaceholder holder) {//TODO auto-generated method stub}}
Above is the Android implementation of the key code to reverse the picture, I hope to help you learn.