The method of drawing circular head in Android application _android

Source: Internet
Author: User

To draw this circle-shaded avatar, the individual breaks down into three layers

1, first draw the edge of the avatar gradient

Radialgradient gradient = new Radialgradient (j/2,k/2,j/2,new int[]{0xff5d5d5d,0xff5d5d5d,0x00ffffff},new float[]{0.f , 0.8f,1.0f}, Shader.TileMode.CLAMP);
Paint.setshader (gradient);
Canvas.drawcircle (J/2,k/2,j/2,paint);

2, cut out the round head bitmap

/** * Convert picture into round * @param bitmap incoming Bitmap Object * @return/Public bitmap Toroundbitmap (bitmap bitmap) {int width = Bi
  Tmap.getwidth ();
  int height = bitmap.getheight ();
  float ROUNDPX;
  float Left,top,right,bottom,dst_left,dst_top,dst_right,dst_bottom;
   if (width <= height) {roundpx = WIDTH/2-5;
   top = 0;
   bottom = width;
   left = 0;
   right = width;
   Height = width;
   Dst_left = 0;
   dst_top = 0;
   Dst_right = width;
  Dst_bottom = width;
   else {roundpx = HEIGHT/2-5;
   Float clip = (width-height)/2;
   left = clip;
   right = Width-clip;
   top = 0;
   bottom = height;
   width = height;
   Dst_left = 0;
   dst_top = 0;
   Dst_right = height;
  Dst_bottom = height;
  Bitmap output = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);
 
  Canvas Canvas = new Canvas (output);
  final int color = 0xff424242;
  Final Paint Paint = new Paint ();
  Final Rect src = new Rect (int) left, (int) top, (int) right, (int) bottom); FinaL Rect DST = new Rect (int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
 
  Final RECTF RECTF = new RECTF (dst_left+15, dst_top+15, dst_right-20, dst_bottom-20);
 
  Paint.setantialias (TRUE);
  Canvas.drawargb (0, 0, 0, 0);
 
  Paint.setcolor (color);
 
  Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);
  Paint.setxfermode (New Porterduffxfermode (PorterDuff.Mode.SRC_IN));
  Canvas.drawbitmap (bitmap, SRC, DST, paint);
 return output;
 }

3, the last painting on the white side

Paint Paint = new Paint ();
   Paint.setcolor (0xFFFFFFFF);
   Paint.setstrokewidth (ten);
   Paint.setstyle (Paint.Style.STROKE);
 
   Canvas.drawcircle (J/2,k/2,j/2-20,paint);

Ps:android app common icon size specification
1. Program Launch icon:
ldpi (Low density screen,120 DPI) with an icon size of X-px.
MDPI (Medium density screen, 160 DPI) with an icon size of X-px.
HDPI (High density screen, at the same size as the DPI), with an icon of X-px.
XHDPI (extra-high density screen, the image DPI) with an icon size of x px.
XXHDPI (xx-high density screen, and the DPI), whose icon size is 144 x 144 px.

2. Bottom menu icon
(1) Large screen:
Full picture (red): X-px
Icon (blue): X (px)
Icon outer frame (pink): x px

(2) Medium screen:
Complete Picture: X-px
Icon: x px
Icon outer border: x px

(3) Small screen:
Complete Picture: x + px
Icon: x px
Icon outline: x px

3. Pop-up dialog box top icon

Small screen x px low density screen (ldpi)
Medium x px Density screen (MDPI)
Da ping x (hdpi) px High density screen

4. long list Internal list item icon

Small screen x px low density screen (ldpi)
Medium x px Density screen (MDPI)
Da ping x (hdpi) px High density screen

5. Bottom or top tab tab icon

(1) Large screen (hdpi) screens:
Full picture (red): px x
Icon (blue): x px

(2) China screen (MDPI) screens:
Complete Picture: x px
Icon: x px

(3) Small screen (ldpi) screens:
Complete Picture: x px
Icon: x px

6. Bottom status bar icon

LDPI (at dpi) x PX small screen
MDPI (160 dpi) x PX Medium screen
HDPI (at the high dpi) x-px Large screen
XHDPI (+ +)-X + PX Super screen

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.