Learn about Android pictures together rounding a picture collection resources (28)

Source: Internet
Author: User

:







Take a look at the following code:

public class Mainactivity extends Activity {private ImageView imageview1;private ImageView imageView2; Bitmap mbitmap; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.image); Initview ();} private void Initview () {imageview1= (ImageView) Findviewbyid (r.id.imageview1); imageview2= (ImageView) Findviewbyid ( R.ID.IMAGEVIEW2);//Read the resource Picture Mbitmap=readbitmap ();//scale the resource picture bitmap Bitmap=zoombitmap (Mbitmap, Mbitmap.getwidth ()/2, Mbitmap.getheight ()/2);//Set fillet picture Imageview2.setimagebitmap (Setroundedcorner (bitmap,20f));} /** * Read Resource picture * @return */private Bitmap readbitmap () {bitmapfactory.options opt=new bitmapfactory.options ();/* * Set to allow decoder to best Mode decoding */opt.inpreferredconfig=bitmap.config.rgb_565;//The following two fields need to be combined using opt.inpurgeable=true;opt.ininputshareable=true ;/* * Get resource Picture */inputstream is=this.getresources (). Openrawresource (R.drawable.mei); return Bitmapfactory.decodestream (IS, null, opt);} /** * Zoom Picture * @param bitmap * @param w * @param h * @return */public  Bitmap Zoombitmap (Bitmap Bitmap, int w, int h) {int width = bitmap.getwidth (); int height = bitmap.getheight (); Matrix matrix = new Matrix (), Float scalewidht = ((float) w/width), Float ScaleHeight = ((float) h/height);/* * via Matrix The Postscale method of the class is scaled */matrix.postscale (SCALEWIDHT, ScaleHeight); Bitmap newbmp = Bitmap.createbitmap (Bitmap, 0, 0, width, height, matrix, true); return newbmp;} /** * Set picture to Fillet * @param bitmap * @param roundpx fillet angle * @return */public bitmap setroundedcorner (bitmap bitmap, float Roun dPx) {Bitmap output = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888); Canvas canvas = new canvas (output), final paint paint = new paint (), final rect rect = new Rect (0, 0, bitmap.getwidth (), Bit Map.getheight ());/* Oval */final RECTF RECTF = new RECTF (rect);/* * antialiasing */paint.setantialias (true); Canvas.drawargb (0, 0, 0, 0);/* Draw Rounded Rectangle */canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);/* * Set two graphs intersect */paint.setxfermode (new Porterduff Xfermode (mode.src_in)); cAnvas.drawbitmap (Bitmap, rect, rect, paint); return output;}} 


Reprint please indicate source:http://blog.csdn.net/hai_qing_xu_kong/article/details/44314043 Emotion Control _

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Learn about Android pictures together rounding a picture collection resources (28)

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.