Android generates bitmap pictures with rounded corners _android

Source: Internet
Author: User

This example describes the Android generation of bitmap pictures with rounded corners. Share to everyone for your reference. Specifically as follows:

Sometimes when we're developing Android apps, we run into fillet images, so how do we use code in Android to generate fillet bitmap pictures? The following code may be able to help you.
This method mainly uses the Drawroundrect to draw the rounded rectangle, then draws the picture through the Drawbitmap.

Generate fillet picture public
static Bitmap Getroundedcornerbitmap (Bitmap Bitmap) {
 try {
  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 (),
    bitmap.getheight ());  
  Final RECTF RECTF = new RECTF (new Rect (0, 0, bitmap.getwidth (),
    bitmap.getheight ()));
  Final float roundpx =;
  Paint.setantialias (true);
  Canvas.drawargb (0, 0, 0, 0);
  Paint.setcolor (color.black);  
  Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);
  Paint.setxfermode (New Porterduffxfermode (mode.src_in));
  Final Rect src = new Rect (0, 0, bitmap.getwidth (),
    bitmap.getheight ());
  Canvas.drawbitmap (bitmap, SRC, rect, paint); 
  return output;
 } catch (Exception e) {return  
  bitmap
 }}


I hope this article will help you with your Android program.

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.