Android--bitmap processing, fillet, round

Source: Internet
Author: User

    /*** Convert picture into circle * *@paramBitmap * Incoming Bitmap Object *@return     */     Public StaticBitmap Toroundbitmap (Bitmap Bitmap) {intwidth =bitmap.getwidth (); intHeight =bitmap.getheight (); floatroundpx; floatLeft , top, right, bottom, Dst_left, Dst_top, Dst_right, Dst_bottom; if(Width <=height) {ROUNDPX= WIDTH/2; Top= 0; Bottom=width; Left= 0; Right=width; Height=width; Dst_left= 0; Dst_top= 0; Dst_right=width; Dst_bottom=width; } Else{roundpx= HEIGHT/2; floatClip = (width-height)/2; Left=clip; Right= width-clip; Top= 0; Bottom=height; Width=height; Dst_left= 0; Dst_top= 0; Dst_right=height; Dst_bottom=height; } Bitmap Output=bitmap.createbitmap (width, height, config.argb_8888); Canvas Canvas=NewCanvas (output); Final intcolor = 0xff424242; FinalPaint paint =NewPaint (); FinalRect src =NewRect (int) Left, (int) Top, (int) Right, (int) bottom); FinalRect DST =NewRect (int) Dst_left, (int) Dst_top, (int) Dst_right, (int) dst_bottom); FinalRECTF RECTF =NewRECTF (DST); Paint.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, SRC, DST, paint); returnoutput; }    /*** to rounded corners bitmap *@paramBitmap *@return     */     Public StaticBitmap Getroundedcornerbitmap (Bitmap Bitmap,floatroundpx) {        Try{Bitmap Output=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888); Canvas Canvas=NewCanvas (output); Final intcolor = 0xff424242;//color value (0xFF---Alpha)            FinalPaint paint =NewPaint (); FinalRect rect =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ()); FinalRECTF RECTF =NewRECTF (rect);//rect is a numeric value using the type int, RECTF is using the float type as the numeric value//--------anti-aliasing-------//Paint.setantialias (true); Canvas.drawargb (0, 0, 0, 0);            Paint.setcolor (color);            Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint); Paint.setxfermode (NewPorterduffxfermode (mode.src_in)); FinalRect src =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ()); Canvas.drawbitmap (Bitmap,NULL, rect, paint); returnoutput; } Catch(Exception e) {e.printstacktrace (); return NULL; }    }

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.