Set picture size and rotation

Source: Internet
Author: User

Xml

<imageview
Android:id= "@+id/img"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:src= "@drawable/left"
Android:scaletype= "Fitcenter"
/>
<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "Drag to change the image size"
Android:textsize= "30px"
/>
<seekbar
Android:id= "@+id/sb"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"

/>
<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "Drag to rotate Picture"
Android:textsize= "30px"
/>
<seekbar
Android:id= "@+id/sb1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"

/>
There are two of Seekbar
SB Implementation Setonseekbarchangelistener (this); interface
SB1 implementation Setonseekbarchangelistener (this); interface
The idea of dragging the scrollbar to zoom is this, first set the max value of SB to the screen width
Then you can change the size of the Imagview container by dragging the return value to change the size of the picture.
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); Get the width of the screen
int w = dm.widthpixels;
Sb.setmax (w); Set the maximum value of SB


Drag the scroll bar to rotate the idea first to declare a matrix matrix = new Matrix ();

This class is used for the operation of the picture. Set the degree of his rotation and then load the resource to create a rotated picture
Set this image to a rotated image.
The rotation of the picture does not really let the picture rotate, but a new or a picture and then let the picture rotate, the rotated image to replace the img


It will rewrite the method object. Drag values
public void onprogresschanged (SeekBar SeekBar, int Pro, Boolean arg2) {
int A=seekbar.getid;
Switch (a)
Case R.ID.SB:
int w = Pro;
int h = PRO*3/4;
Linearlayout.layoutparams pra = new Linearlayout.layoutparams (w, h);
Img.setlayoutparams (PRA);
Break

Case R.ID.SB1:
Matrix.setrotate (PRO);
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.left);
Bitmap bit = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (),
Bitmap.getheight (), Matrix, True);//Create a rotated picture with a return value of bitmap to create a new bitmap to receive
Img.setimagebitmap (bit); Replace the rotated picture with this picture
Break

}

Set picture size and 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.