Android Picture Rounded corners

Source: Internet
Author: User
/** * Convert picture to fillet picture * * @param drawable * @param roundpx * @return * * private static BITMA
        P getroundcornerdrawable (drawable drawable, float roundpx/* fillet radius * *) {int w = drawable.getintrinsicwidth ();

        int h = drawable.getintrinsicheight (); Bitmap Bitmap = Bitmap.createbitmap (W, H, drawable.getopacity ()!= pixelformat.opaque?

        Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565);
        Canvas Canvas = new Canvas (bitmap);
        Drawable.setbounds (0, 0, W, h);

        Drawable.draw (canvas);
        int width = bitmap.getwidth ();
        int height = bitmap.getheight ();
        Bitmap retbmp = bitmap.createbitmap (width, height, config.argb_8888);

        Canvas can = new Canvas (retbmp);
        final int color = 0xff424242;
        Final Paint Paint = new Paint ();
        Final Rect Rect = new Rect (0, 0, width, height);

        Final RECTF RECTF = new RECTF (rect);
        Paint.setcolor (color); Paint.setanTialias (TRUE);
        Can.drawargb (0, 0, 0, 0);

        Can.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);
        Paint.setxfermode (New Porterduffxfermode (mode.src_in));
        Can.drawbitmap (Bitmap, rect, rect, paint);
        return new bitmapdrawable (retbmp);
    return retbmp; }

Related Article

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.