Android 截取圆形图片核心代码

好用,呵呵(http://www.eoeandroid.com/thread-103093-1-1.html)

 

int targetWidth = 100;
int targetHeight = 100;
Bitmap targetBitmap = Bitmap.createBitmap(
targetWidth,
targetHeight,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(
((float)targetWidth - 1) / 2,
((float)targetHeight - 1) / 2,
(Math.min(((float)targetWidth), ((float)targetHeight)) / 2),
Path.Direction.CCW);
canvas.clipPath(path);
Bitmap sourceBitmap = BitmapFactory.decodeResource(
getResources(),
R.drawable.my_image);
canvas.drawBitmap(
sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
null);
ImageView imageView = (ImageView)findViewById(R.id.my_image_view);
imageView.setImageBitmap(targetBitmap);

 

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据