"Android" Fillet avatar

Source: Internet
Author: User

I: Draw fillet:

1     Private voidroundimg (ImageView iv) {2 3     /**Local Resources*/4 5InputStream is =getresources (). Openrawresource (R.drawable.icon);6 7Bitmap Bitmap =Bitmapfactory.decodestream (IS);8 9     /**network resources*/Ten  One     //FileInputStream fis = new FileInputStream (URL); A  -     //Bitmap Bitmap = Bitmapfactory.decodestream (FIS); -  the       if(Bitmap! =NULL){ -  -Bitmap Zoombitmap = Imageutil.zoombitmap (bitmap,100,100); -  +Bitmap Roundbitmap = Imageutil.getroundedcornerbitmap (zoombitmap,50.0f); -  + Iv.setimagebitmap (roundbitmap); A  at } -  -}

Ii:imageutil Tool Class

1  Public classImageutil {2 3      Public StaticBitmap Zoombitmap (Bitmap Bitmap,intWinth) {4 5         intwidth =bitmap.getwidth ();6         intHeight =bitmap.getheight ();7         /**8          * 9          */TenMatrix Matrix =NewMatrix (); One         floatScaleWidth = (float) w/width; A         floatScaleHeight = (float) H/height; - Matrix.postscale (ScaleWidth, scaleheight); -Bitmap newbmp = Bitmap.createbitmap (Bitmap, 0, 0, width, height, matrix,true); the         returnnewbmp; -     } -  -      +      Public StaticBitmap Drawabletobitmap (drawable drawable) { -         intwidth = Drawable.getintrinsicwidth (); +         intHeight =drawable.getintrinsicheight (); ABitmap Bitmap =bitmap.createbitmap (width, height, atDrawable.getopacity ()! = Pixelformat.opaque?Bitmap.Config.ARGB_8888 - : Bitmap.Config.RGB_565); -Canvas Canvas =NewCanvas (bitmap); -Drawable.setbounds (0, 0, width, height); - Drawable.draw (canvas); -         returnbitmap; in     } -  to      +      Public StaticBitmap Getroundedcornerbitmap (Bitmap Bitmap,floatroundpx) { -  theBitmap output =Bitmap * . CreateBitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888); $Canvas Canvas =NewCanvas (output);Panax Notoginseng         Final intcolor = 0xff424242; -         FinalPaint paint =NewPaint (); the         FinalRect rect =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ()); +         FinalRECTF RECTF =NewRECTF (rect); A  thePaint.setantialias (true); +Canvas.drawargb (0, 0, 0, 0); - paint.setcolor (color); $ Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint); $  -Paint.setxfermode (NewPorterduffxfermode (mode.src_in)); - canvas.drawbitmap (Bitmap, rect, rect, paint); the         returnoutput; -     }Wuyi  the      Public StaticBitmap createreflectionimagewithorigin (Bitmap Bitmap) { -         Final intReflectiongap = 4; Wu         intwidth =bitmap.getwidth (); -         intHeight =bitmap.getheight (); About  $Matrix Matrix =NewMatrix (); -Matrix.prescale (1,-1); -  -Bitmap Reflectionimage =Bitmap.createbitmap (Bitmap, A0, HEIGHT/2, width, height/2, matrix,false); +  theBitmap bitmapwithreflection = bitmap.createbitmap (width, height + height/2), - config.argb_8888); $  theCanvas Canvas =NewCanvas (bitmapwithreflection); theCanvas.drawbitmap (bitmap, 0, 0,NULL); thePaint Deafalutpaint =NewPaint (); theCanvas.drawrect (0, height, width, height +Reflectiongap, - deafalutpaint); in  theCanvas.drawbitmap (reflectionimage, 0, height + reflectiongap,NULL); the  AboutPaint paint =NewPaint (); theLinearGradient shader =NewLinearGradient (0, theBitmap.getheight (), 0, Bitmapwithreflection.getheight () the+ Reflectiongap, 0X70FFFFFF, 0X00FFFFFF, Tilemode.clamp); + Paint.setshader (shader); -         //Set the Transfer mode to being Porter Duff and destination in thePaint.setxfermode (NewPorterduffxfermode (mode.dst_in));Bayi         //Draw a rectangle using the paint with our linear gradient theCanvas.drawrect (0, height, width, bitmapwithreflection.getheight () the+reflectiongap, paint); -  -         returnbitmapwithreflection; the     } the      the}

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.