Android realizes picture reversal effect _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.