Image shape rounded corner, shape rounded corner

Source: Internet
Author: User

Image shape rounded corner, shape rounded corner

Be sure to convert to PNG format first, otherwise it will be opaque


1/** 2 * convert the image into a circle. 3*4 * @ param bitmap 5 * import Bitmap object 6 * @ return 7 */8 public Bitmap toRoundBitmap (Bitmap bitmap) {9 int width = bitmap. getWidth (); 10 int height = bitmap. getHeight (); 11 float roundPx; 12 float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; 13 if (width <= height) {14 roundPx = width/2; 15 left = 0; 16 top = 0; 17 right = width; 18 bottom = width; 19 height = wi Dth; 20 dst_left = 0; 21 dst_top = 0; 22 dst_right = width; 23 dst_bottom = width; 24} else {25 roundPx = height/2; 26 float clip = (width-height)/2; 27 left = clip; 28 right = width-clip; 29 top = 0; 30 bottom = height; 31 width = height; 32 dst_left = 0; 33 dst_top = 0; 34 dst_right = height; 35 dst_bottom = height; 36} 37 38 Bitmap output = Bitmap. createBitmap (width, height, Config. ARGB_8888); 39 Canva S canvas = new Canvas (output); 40 41 final int color = 0xff0000242; 42 final Paint paint = new Paint (); 43 final Rect src = new Rect (int) left, (int) top, (int) right, 44 (int) bottom); 45 final Rect dst = new Rect (int) dst_left, (int) dst_top, 46 (int) dst_right, (int) dst_bottom); 47 final RectF rectF = new RectF (dst); 48 49 paint. setAntiAlias (true); // set the paint brush to 50 51 canvas. drawARGB (0, 0, 0, 0); // fill in the entire C Anvas52 paint. setColor (color); 53 54 // The following two methods are used to draw circles, drawRounRect and drawCircle55 // canvas. drawRoundRect (rectF, roundPx, roundPx, paint); // 56 // draw a rounded rectangle. The first parameter is the graphic display area, the second and third parameters are the radius of the horizontal and vertical rounded corners. 57 canvas. drawCircle (roundPx, paint); 58 59 paint. setXfermode (new porterduduxfermode (Mode. SRC_IN); // set the pattern when two images are intersecting, refer to the http://trylovecatch.iteye.com/blog/118945260 canvas. drawBitmap (bitmap, src, dst, paint); // In Mode. merge bitmap with Circle61 62 return output; 63} In SRC_IN Mode}

 

1 // The rectangle turns the four corners of the image into 2 public static Bitmap getRoundedCornerBitmap (Bitmap bitmap) {3 Bitmap output = Bitmap. createBitmap (bitmap. getWidth (), 4 bitmap. getHeight (), Config. ARGB_8888); 5 // Get Canvas 6 canvas Canvas = new Canvas (output); 7 // round the four corners of the canvas to 8 final int color = Color. RED; 9 final Paint paint = new Paint (); 10 // obtain the location and size of the region of the same size as the image determined by the constructed four values 11 final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight (); 12 final RectF rectF = new RectF (rect); 13 // The larger the value, the more obvious the angle. 14 final float roundPx = 30; 15 paint. setAntiAlias (true); 16 canvas. drawARGB (0, 0, 0, 0); 17 paint. setColor (color); 18 // The second and second parameters of drawRoundRect are the same, and the corner of the positive circle is drawn. If the values are different, the corner of the ellipse is 19 canvas. drawRoundRect (rectF, roundPx, roundPx, paint); 20 paint. setXfermode (new porterduduxfermode (Mode. SRC_IN); 21 canvas. drawBitmap (bitmap, rect, rect, paint); 22 return output; 23}

 


How to PS the image rounded corner shape

Does the landlord mean a border with rounded corners?
Baidu search has many such tutorials.
The following is a brief introduction.
1. Double-click "background image" in the "layer" window in the lower right corner to unlock
2. Right-click "rectangle tool" on the toolbar and select "corner rectangle tool (below the text tool )"
3. Set the attributes of the tool in the option bar under the menu bar. (Change "pattern tool" to "path" and "radius" to set the Radian of the rounded corner. The larger the value is, the closer the angle is)
4. Drag the desired size in the figure. ctrl + press enter to create a constituency. ctrl + shift + I reverse select the constituency. Then press Del to delete the constituency.
5. The storage is in PNG format.

Note:
1. The rounded rectangle tool is a path tool rather than a selection tool (LZ uses a selection tool)
2. the rounded rectangle tool contains the following six shapes: rectangle, rounded corner, elliptical shape, polygon, straight line, and custom shape.

PS How can I change the image shape to a rounded rectangle? Graph

Ps has a rounded rectangle tool (shortcut: U)
After selecting the rounded rectangle tool, adjust the angle of the rounded corner using the radius value on the toolbar.
Draw the rectangular path of the rounded corner on the graph.
Ctrl + Enter into the selection area, Ctrl + Shift + I invert selection, Delete the corner
Save it ~
If the image is saved as jpg, the deleted corner is white.
Save as png, And the deleted part will become transparent ~ (But remember to delete the background layer together)
This is probably the case. If you have any questions, I will try my best to answer them ~

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.