Android bitmap zoomin/zoomout/rotate -- zoom in, zoom in, and rotate an image

Source: Internet
Author: User
Java code
  1. Public void oncreate (bundle icicle ){
  2. Super. oncreate (icicle );
  3. Linearlayout linlayout = new linearlayout (this );
  4. // Load the image to be operated. Here is the logo image of eoeandroid.
  5. Bitmap bitmaporg = bitmapfactory. decoderesource (getresources (),
  6. R. drawable. Icon );
  7. // Obtain the width and height of the image.
  8. Int width = bitmaporg. getwidth ();
  9. Int Height = bitmaporg. getheight ();
  10. // Define the width and height of the pre-converted Image
  11. Int newwidth = 200;
  12. Int newheight = 200;
  13. // Calculate the zooming rate. The new size excludes the original size.
  14. Float scalewidth = (float) newwidth)/width;
  15. Float scaleheight = (float) newheight)/height;
  16. // Create a matrix object for image operations
  17. Matrix matrix = new matrix ();
  18. // Scaling the image
  19. Matrix. postscale (scalewidth, scaleheight );
  20. // Rotate the image
  21. Matrix. postrotate (45 );
  22. // Create a new image
  23. Bitmap resizedbitmap = bitmap. createbitmap (bitmaporg, 0, 0, width,
  24. Height, matrix, true );
  25. // Convert the bitmap created above to a drawable object so that it can be used in imageview and imagebutton.
  26. Bitmapdrawable BMI = new bitmapdrawable (resizedbitmap );
  27. // Create an imageview
  28. Imageview = new imageview (this );
  29. // Set the image of imageview to the image converted above
  30. Imageview. setimagedrawable (BMI );
  31. // Center the image
  32. Imageview. setscaletype (scaletype. center );
  33. // Add the imageview to the layout Template
  34. Linlayout. addview (imageview, new linearlayout. layoutparams (
  35. Layoutparams. fill_parent, layoutparams. fill_parent ));
  36. // Set this activity Template
  37. Setcontentview (linlayout );
  38. }

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.