图片画圆
来源:互联网 发布:蒙草堂亚麻籽油淘宝网 编辑:程序博客网 时间:2024/04/29 02:50
public class Imageview_ extends ImageView {
public Imageview_(Context context) {
super(context);
}
public Imageview_(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Imageview_(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable)drawable).getBitmap() ;
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
Bitmap roundBitmap = getCroppedBitmap(bitmap, getWidth());
canvas.drawBitmap(roundBitmap, 0, 0, null);
}
/*
* 对Bitmap裁剪,使其变成圆形,这步最关键
*/
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
Bitmap sbmp;
if(bmp.getWidth() != radius || bmp.getHeight() != radius)
sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
else
sbmp = bmp;
Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
paint.setColor(Color.parseColor("#BAB399"));
Canvas c = new Canvas(output);
c.drawARGB(0, 0, 0, 0);
c.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f, sbmp.getWidth() / 2+0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
c.drawBitmap(sbmp, rect, rect, paint);
return output;
}
}
public Imageview_(Context context) {
super(context);
}
public Imageview_(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Imageview_(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable)drawable).getBitmap() ;
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
Bitmap roundBitmap = getCroppedBitmap(bitmap, getWidth());
canvas.drawBitmap(roundBitmap, 0, 0, null);
}
/*
* 对Bitmap裁剪,使其变成圆形,这步最关键
*/
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
Bitmap sbmp;
if(bmp.getWidth() != radius || bmp.getHeight() != radius)
sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
else
sbmp = bmp;
Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
paint.setColor(Color.parseColor("#BAB399"));
Canvas c = new Canvas(output);
c.drawARGB(0, 0, 0, 0);
c.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f, sbmp.getWidth() / 2+0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
c.drawBitmap(sbmp, rect, rect, paint);
return output;
}
}
0 0
- 图片画圆
- 图片画圆
- 图片画圆
- 图片----图片加载框架:Fresco--头像画圆
- 圆图片
- 图片倒影+圆角图片
- 图片绕某一圆心画圆
- android 图片处理(图片合成、图片圆角、图片翻转、图片缩放)
- 自定义圆形图片、圆角图片,椭圆图片
- Glide使用 加载网络图片 圆形图片 圆角图片
- Android 图片缩放,图片圆角处理
- Android 圆角图片和灰度图片
- android圆角图片和图片倒影
- 【Android】 图片编辑:创建圆角图片
- iOS 设置圆形图片、圆角图片
- Android图片操作-获得圆角图片
- iOS 设置圆形图片、圆角图片
- 自定义圆角矩形图片/圆形图片
- Cow Bowling 数字三角形 初步动态规划
- 多项式求和
- linux下怎么挂载U盘
- 《骗子日记》
- KVC/KVO原理详解及编程指南
- 图片画圆
- Pie
- 树莓派 Learning 002 装机后的必要操作 --- 03 替换软件源
- 如何清洗和保养工业相机
- Form good habits----TimeManger(daily report)
- java 整合redis缓存 SSM 后台框架
- 设计模式-中介者模式
- Objective-C之run loop详解
- 分布式控制系统Git学习网站