展会信息港展会大全

android开发之ImageView绘制圆形
来源:互联网   发布日期:2015-10-03 11:21:19   浏览:2055次  

导读: ** * Returns a circular cropped version of the bitmap passed in * public static Bitmap getCroppedBitmap(Bitmap bitmap) { Bitmap output = Bitmap createBitmap(bi ...

/**

* Returns a circular cropped version of the bitmap passed in.

*/

public static Bitmap getCroppedBitmap(Bitmap bitmap) {

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

Config.ARGB_8888);

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

Canvas canvas = new Canvas(output);

final Paint paint = new Paint();

paint.setAntiAlias(true);

int halfWidth = bitmap.getWidth() / 2;

int halfHeight = bitmap.getHeight() / 2;

canvas.drawCircle(halfWidth, halfHeight, Math.max(halfWidth, halfHeight), paint);

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

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

return output;

}

赞助本站

人工智能实验室

相关热词: ImageView 绘制圆形 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港