How to generate rounded corner images in android

Source: Internet
Author: User

How to generate rounded corner images in android

This article mainly introduces how to generate a rounded corner image in android, which involves the skills for Android to process rounded corner images. For more information, see

This document describes how to generate a rounded corner image in android. Share it with you for your reference. The specific analysis is as follows:

In android development, the image view is often required to display the effect of the rounded corner image. How can this problem be achieved?

Here we summarize the optimal method on the Internet: process the image into a rounded corner and load it to the ImageView for display. The Code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

Public Bitmap getRoundedCornerBitmap (Bitmap bitmap, int pixels ){

Bitmap output = Bitmap. createBitmap (bitmap. getWidth (), bitmap

. GetHeight (), Config. ARGB_8888 );

Canvas canvas = new Canvas (output );

Final int color = 0xff0000242;

Final Paint paint = new Paint ();

Final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight ());

Final RectF rectF = new RectF (rect );

Paint. setAntiAlias (true );

Canvas. drawARGB (0, 0, 0, 0 );

Paint. setColor (color );

Canvas. drawRoundRect (rectF, pixels, pixels, paint );

Paint. setXfermode (new porterduxfermode (Mode. SRC_IN ));

Canvas. drawBitmap (bitmap, rect, rect, paint );

Return output;

}

Attached:

There is no problem with this method. However, if the loaded image is too large, this method will take a long time. In this way, for a large number of imageviews, refreshing will cause freezing or blinking problems, how can this problem be solved?

In my opinion, if this is the case, we can only discard this method. Second, we can build two layers of ImageView. The first layer is the original square corner image, the second layer is A special resource map B, which is the same size as the source image, we suppose A according to the above method to obtain the rounded corner image is C, then define the image T = A-C, then we change T to the background color we need. In this way, B = T (background color). The final effect is that A is below, B is above, and four corners are rounded corners, the square angle image is covered under B. This saves time-consuming problems caused by direct image processing. However, if the image size is small and the number of images is small, I suggest using the first method. After all, the original version has a good effect. Piracy is still pirated!

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.