Glide加载圆形图
Glide.with(context).load(url).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(view);
Glide加载圆角
Glide.with(context).load(url).apply(RequestOptions.bitmapTransform(new RoundedCorners(圆角度数))).into(view);
Bitmap 修改为圆形图
原理:解析bitmap 重新绘制
public Bitmap toRoundBitmap(Bitmap bitmap) {
bitmap = Bitmap.createScaledBitmap(bitmap, 400, 400, true);
Bitmap bm = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bm);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// 这里需要先画出一个圆
canvas.drawCircle(200, 200, 200, paint);
// 圆画好之后将画笔重置一下
paint.reset();
// 设置图像合成模式,该模式为只在源图像和目标图像相交的地方绘制源图像
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
return bm;
}
dp值转换成代码中的int值
int v1 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, getResources().getDisplayMetrics());
Android 中 图片的拼接思路
public static Bitmap toConformBitmap(Bitmap head, Bitmap body, Bitmap san) {
if (head == null) {
return null;
}
int headWidth = head.getWidth();
int bodywidth = body.getWidth();
int fotwid = san.getWidth();
int headHeight = head.getHeight();
int bodyheight = body.getHeight();
int footerheight = san.getHeight();
//生成三个图片合并大小的Bitmap
Bitmap newbmp = Bitmap.createBitmap(bodywidth, headHeight + bodyheight + footerheight, Bitmap.Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
cv.drawBitmap(head, 0, 0, null);// 在 0,0坐标开始画入headBitmap
//因为手机不同图片的大小的可能小了 就绘制白色的界面填充剩下的界面
if (headWidth < bodywidth) {
Bitmap ne = Bitmap.createBitmap(kebianwidth - headWidth, headHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(ne);
canvas.drawColor(Color.WHITE);
cv.drawBitmap(ne, headWidth, 0, null);
}
cv.drawBitmap(body, 0, headHeight, null);// 在 0,headHeight坐标开始填充课表的Bitmap
cv.drawBitmap(san, 0, headHeight + bodyheight, null);// 在 0,headHeight +bodyheight坐标开始填充课表的Bitmap
//因为手机不同图片的大小的可能小了 就绘制白色的界面填充剩下的界面
if (fotwid < bodywidth) {
Bitmap ne = Bitmap.createBitmap(bodywidth - fotwid, footerheight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(ne);
canvas.drawColor(Color.WHITE);
cv.drawBitmap(ne, fotwid, headHeight + bodyheight, null);
}
cv.save(Canvas.ALL_SAVE_FLAG);// 保存
cv.restore();// 存储
//回收
head.recycle();
body.recycle();
san.recycle();
return newbmp;
}