:
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)