zooming, rotating, and panning of pictures

Source: Internet
Author: User

1. View

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical"6 Tools:context=". Mainactivity " >7 8     <ImageView9         Android:id= "@+id/iv_1"Ten Android:layout_width= "Wrap_content" One Android:layout_height= "Wrap_content" A         /> -      -     <ImageView the         Android:id= "@+id/iv_2" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" -          /> +  - </LinearLayout>

2. Code

1  Packagecom.example.imageresize;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.graphics.Bitmap;6 Importandroid.graphics.BitmapFactory;7 ImportAndroid.graphics.Canvas;8 ImportAndroid.graphics.Color;9 ImportAndroid.graphics.Matrix;Ten ImportAndroid.graphics.Paint; One ImportAndroid.view.Menu; A ImportAndroid.widget.ImageView; -  -  Public classMainactivityextendsActivity { the  -     PrivateImageView iv_1; -     PrivateImageView iv_2; - @Override +     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); A          atIv_1 =(ImageView) Findviewbyid (r.id.iv_1); -Iv_2 =(ImageView) Findviewbyid (r.id.iv_2); -          -Bitmap Bitmap1 =Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); - Iv_1.setimagebitmap (BITMAP1); -          inBitmap Alterbitmap = Bitmap.createbitmap (bitmap1.getwidth () + Ten, bitmap1.getheight () + 10, Bitmap1.getconfig ()); -Canvas Canvas =NewCanvas (alterbitmap); toPaint paint =NewPaint (); + Paint.setcolor (color.black); -Matrix Matrix =NewMatrix (); the         /*************** Picture Scaling code start******************/ *         //Note the x-axis and y-axis scaling $        /*matrix.setvalues (New float[]{Panax Notoginseng 2.0f,0,1, - 0,1,0, the 0,0,1 +         });*/ A         //Matrix.setscale (2.0f, 1); the         /*************** Picture Scaling code end******************/ +         //matrix.setrotate (Bitmap1.getwidth ()/2, Bitmap1.getheight ()/2); -         //Matrix.setrotate (a); $         /*********** Mirror Effect start*************/ $Matrix.setscale (-1, 1); -Matrix.posttranslate (Bitmap1.getwidth (), 0);//This setting is panning -         /*********** Mirror Effect end*************/ the         //Matrix.settranslate (ten);//x and y axes move 10 pixels -         //draw into the canvas with Bitmap1 as a templateWuyi Canvas.drawbitmap (Bitmap1, Matrix, paint); the Iv_2.setimagebitmap (alterbitmap); -     } Wu  -  About      $}

zooming, rotating, and panning of pictures

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.