Android learning history UI ----- imageView: rotating and scaling Images

Source: Internet
Author: User

Android learning history UI ----- imageView: rotating and scaling Images

I feel it will be nice to write and parse in the code. I will directly use the method used for parsing in the program code.


MainActivity:

Package com. example. imageview_demo03; import android. support. v7.app. actionBarActivity; import android. util. displayMetrics; import android. annotation. suppressLint; import android. graphics. bitmap; import android. graphics. matrix; import android. graphics. drawable. bitmapDrawable; import android. OS. bundle; import android. widget. imageView; import android. widget. linearLayout; import android. widget. seekBar; import and Roid. widget. textView; import android. widget. seekBar. extends; @ SuppressLint ("NewApi") public class MainActivity extends ActionBarActivity implements extends {// the smallest scaling width is private int minWidth = 80; private ImageView imageView; private SeekBar seekBar1; private SeekBar seekBar2; private TextView textView1; private TextView textView2; // Matrix class, used to rotate the image private matrix Matrix = new Matri X (); @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); imageView = (ImageView) findViewById (R. id. imageView); seekBar1 = (SeekBar) findViewById (R. id. seekBar1); seekBar2 = (SeekBar) findViewById (R. id. seekBar2); seekBar1.setOnSeekBarChangeListener (this); seekBar2.setOnSeekBarChangeListener (this); textView1 = (TextView) findVie WById (R. id. textview1); textView2 = (TextView) findViewById (R. id. textview2); // create an empty display matrix to store the current screen information, such as the size. DisplayMetrics displayMetrics = new DisplayMetrics (); // transmits the currently managed screen size to displayMetricsgetWindowManager (). getdefadisplay display (). getMetrics (displayMetrics); // you can specify a maximum value of seekBar1.setMax (displayMetrics. widthPixels-minWidth) ;}@ Overridepublic void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {if (seekBar. getId () = R. id. seekBar1) {// set the width to 80 to the maximum int mwidth = progress + minWidth; int mheight = (int) (2 * mwidth/3 ); // set the imageView output size parameter // because the image is a fitcenter parameter, therefore, the image size changes with the size of the image framework. // changing the size of the image framework will change the image size, so that the image can be enlarged or reduced. setLayoutParams (new LinearLayout. layoutParams (mwidth, mheight); textView1.setText ("Image Width:" + mwidth + "\ t Image Height:" + mheight);} else if (seekBar. getId () = R. id. seekBar2) {// The setRotation method of imageView itself is to rotate clockwise around the center of the image. // The rotation does not change the output size of imageView, the part that exceeds the imageView is displayed at the bottom of the view. // imageView. setRotation (progress); // if you want to create a rotated image that does not exceed the imageView output frame, you need to take the original image out and rotate it, re-import to imageView // defect: occupying a large amount of memory, it will compare the card Bitmap bitmap = (BitmapDrawable) (getResources (). getDrawable (R. drawable. photo ))). getBitmap (); matrix. setRotate (progress); bitmap = Bitmap. createBitmap (bitmap, 0, 0, bitmap. getWidth (), bitmap. getHeight (), matrix, true); imageView. setImageBitmap (bitmap); textView2.setText ("image rotation" + progress + "degree") ;}@ Overridepublic void onStartTrackingTouch (SeekBar seekBar) {// TODO Auto-generated method stub} @ Overridepublic void onStopTrackingTouch (SeekBar seekBar) {// TODO Auto-generated method stub }}

Xml:

     
      
      
      
      
  
 

Running legend:


If there is something wrong with the text or you have a better method, please contact us.

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.