当前位置: 代码迷 >> Android >> 圆形裁剪图片的代码小弟我该如何加啊有代码~
  详细解决方案

圆形裁剪图片的代码小弟我该如何加啊有代码~

热度:77   发布时间:2016-04-28 07:23:09.0
圆形裁剪图片的代码我该怎么加啊????有代码~!



所有方法如上面三个图,圆形裁剪的代码如下:
public Bitmap toRoundBitmap(Bitmap bitmap) {                 
int width = bitmap.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;                         
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;                        
 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, Config.ARGB_8888);                
 Canvas canvas = new Canvas(output);                                  
 final int color = 0xff424242;                 
  相关解决方案