Android 气泡图片

释放双眼,带上耳机,听听看~!

效果

setChatImg(bitmap, holder.iv_left_img, R.drawable.pic_07);

R.drawable.pic_07图片样式:

private void setChatImg(Bitmap base64,ImageView v,int drawable) {
try {
Bitmap bitmap_bg = BitmapFactory.decodeResource(getResources(), drawable);
Bitmap bitmap_in =base64;
if(bitmap_in==null){
bitmap_in = BitmapFactory.decodeResource(getResources(),R.drawable.default_loading);
}
Bitmap newbm = zoomImg(bitmap_in, 360, 360);
Bitmap bp = getRoundCornerImage(bitmap_bg, newbm);
v.setImageBitmap(bp);
Log.d("setImageBitmap","setImageBitmap=");
} catch (Exception e) {
e.printStackTrace();
}
}

/**
*  处理图片
* @param bm 所要转换的bitmap
* @param newWidth新的宽
* @param newHeight新的高
* @return 指定宽高的bitmap
*/
public Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片   www.2cto.com
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}  

public static Bitmap getRoundCornerImage(Bitmap bitmap_bg, Bitmap bitmap_in) {
Bitmap roundConcerImage = Bitmap.createBitmap(bitmap_in.getWidth(), bitmap_in.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(roundConcerImage);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap_in.getWidth(), bitmap_in.getHeight());
Rect rectF = new Rect(0, 0, bitmap_in.getWidth(), bitmap_in.getHeight());
paint.setAntiAlias(true);
NinePatch patch = new NinePatch(bitmap_bg, bitmap_bg.getNinePatchChunk(), null);
patch.draw(canvas, rect);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap_in, rectF, rect, paint);
return roundConcerImage;
}

为TA充电
共{{data.count}}人
人已赞赏
Android文章

Android 使用信鸽推送

2021-5-6 11:35:43

Android文章

Android 7.0 获取自定义权限

2021-5-6 12:09:24

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索