Android--ImageView (controls the size of the image and the angle of rotation)

Source: Internet
Author: User

1.

2. Implementing the Code

Package Com.example.myimageview3;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.matrix;import Android.graphics.drawable.bitmapdrawable;import Android.os.Bundle;import Android.util.displaymetrics;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.seekbar;import Android.widget.seekbar.onseekbarchangelistener;import Android.widget.TextView; Import Android.widget.toast;public class Mainactivity extends Activity implements Onseekbarchangelistener {private int MinWidth = 80;/* ImageView picture */private ImageView imageview;/* display picture information as well as angles */private TextView textView1, textview2;/* size and Angle drag bar */private SeekBar seekBar1, seekbar2;/* angle variation matrix */private matrices matrix = new Matrix (); @ overrideprotected void O   Ncreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);// Find Component ImageView = (ImageView) This.findviewbyid (r.id.imageview1); textView1 = (TextView) this.finDviewbyid (r.id.textview1); textView2 = (TextView) This.findviewbyid (r.id.textview2); seekBar1 = (SeekBar) this.fin Dviewbyid (r.id.seekbar1); seekBar2 = (SeekBar) This.findviewbyid (R.ID.SEEKBAR2);//Set Listener events Seekbar1.setonseekbarchan Gelistener, Seekbar2.setonseekbarchangelistener (this);//Get general information about the current phone display and put some information about the current window in Displaymetrics Medium displaymetrics DM = new Displaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getme Trics (DM);//Set the maximum value of seekBar1 to get the screen's pixel -80seekbar1.setmax (dm.widthpixels-minwidth);}                              /* Seekbar listener event */@ overridepublic void onprogresschanged (Seekbar Seekbar, int progress, Boolean Fromuser) {//SEEKBAR1 handling Event//TODO auto-generated method Stubif (seekbar.getid () = = R.id.seekbar1) {//Picture new width int newwidth = progress + minwidth;//Picture The new height is width of 3/4int newheight = (int) (newwidth * 3/4);//The function of scaling according to the original picture//Setting the height and width of the picture         Degree Imageview.setlayoutparams (new Linearlayout.layoutparams (                     Newwidth, Newheight));//Set TextView1 display information Textview1.settext ("Image width" + newwidth + "image height" + newheight);}                              SEEKBAR2 Processing Event Else if (seekbar.getid () = = r.id.seekbar2) {Bitmap Bitmap = ((bitmapdrawable) (Getresources () . Getdrawable (R.drawable.dog)). Getbitmap ();//Set the angle of the picture rotation matr                              Ix.setrotate (progress); bitmap = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bit Map.getheight (), Matrix, True); Imageview.setimagebitmap (b ITMAP); Textview2.settext (Progress + "degree");}} @ overridepublic void Onstarttrackingtouch (SeekBar SeekBar) {//TODO auto-generated method stubtoAst.maketext (Mainactivity.this, "Start dragging", Toast.length_short) . Show (); @ overridepublic void Onstoptrackingtouch (SeekBar SeekBar) {//TODO auto-generated method Stubtoast.maketext (mainacti Vity.this, "Stop dragging", Toast.length_short). Show ();}}

Android--ImageView (controls the size of the image and the angle of rotation)

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.