(Android) processing picture into a circle

Source: Internet
Author: User

It is very common for Android to treat a piece of bitmap as a circle, and the common occasion is to use the canvas to assist with this function, as shown in the following code

1  Public StaticBitmap Toroundcorner (Bitmap Bitmap,intpixels) {2Bitmap output =Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888);3Canvas Canvas =NewCanvas (output);4         Final intcolor = 0xff424242;5         FinalPaint paint =NewPaint ();6         FinalRect rect =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ());7         FinalRECTF RECTF =NewRECTF (rect);8         Final floatROUNDPX =pixels;9Paint.setantialias (true);TenCanvas.drawargb (0, 0, 0, 0); One paint.setcolor (color); A Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint); -Paint.setxfermode (NewPorterduffxfermode (mode.src_in)); - canvas.drawbitmap (Bitmap, rect, rect, paint); the         returnoutput; -}

Pixels is the radius of the image

(Android) processing picture into a circle

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.