关闭

获取六边形头像(封装六边形方法)

标签: android六边形
233人阅读 评论(3) 收藏 举报


//画六边形封装的方法,调用的话当数据成功加载下来的时候再调用

public static Bitmap getSixBitmap(Bitmap bitmap) {  

int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap output = Bitmap.createBitmap(width,  
       height, Config.ARGB_8888);  
   Canvas canvas = new Canvas(output);  
  
   final int color = 0xff424242;  
   final Paint paint = new Paint();  
  
   paint.setAntiAlias(true);  
   canvas.drawARGB(0, 0, 0, 0);  
   paint.setColor(color);  
   
   
   float centerX = width/2;
       float centerY = height/2;
       float radius = width/2;
       double radian30 = 30*Math.PI/180;
       float a = (float) (radius*Math.sin(radian30));
       float b = (float) (radius*Math.cos(radian30));


       Path localPath = new Path();
       localPath.moveTo(centerX, 0);
       localPath.lineTo(centerX+b, centerY-a);
       localPath.lineTo(centerX+b, centerY+a);
       localPath.lineTo(centerX, height);
       localPath.lineTo(centerX-b, centerY+a);
       localPath.lineTo(centerX-b, centerY-a);
       localPath.close();
       
       canvas.drawPath(localPath, paint);
       
   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  
   canvas.drawBitmap(bitmap, 0.0f, 0.0f, paint);  
  
   return output;  

}



/**

* @Name: loadAvatarImage 

* @Description: 获取六边形头像

* @param  url

* @param  imageView    

* @return void    返回类型 

* @throws 

*

*/

public static void loadHexagonAvatarImage(String url, ImageView imageView){

if(url == null || url.length() <= 0)

return;

DisplayImageOptions options = new DisplayImageOptions.Builder()

.cacheOnDisc(true)

.cacheInMemory(false)

.showImageOnLoading(R.drawable.home_user_avatar_default)

.showImageOnFail(R.drawable.home_user_avatar_default)

.build();

ImageLoader.getInstance().displayImage(url, imageView, options, new SimpleImageLoadingListener(){

@Override

public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

if(loadedImage != null)

((ImageView)view).setImageBitmap(getHexagonBitmap(loadedImage));

super.onLoadingComplete(imageUri, view, loadedImage);

}

});

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8178次
    • 积分:223
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:0篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论