BitMap工具类

//获取图片的缩略图 
public Static Bitmap getBitmapThumbnail(String filePath){ 

BitmapFactory.Options options=new BitmapFactory.Options(); 
//true那么将不返回实际的bitmap对象,不给其分配内存空间但是可以得到一些解码边界信息即图片大小等信息 
options.inJustDecodeBounds=true; 
//此时rawBitmap为null 
Bitmap rawBitmap = BitmapFactory.decodeFile(filePath, options); 
if (rawBitmap==null) { 
System.out.println("此时rawBitmap为null"); 

return rawBitmap
}


public Bitmap toRoundCorner(Bitmap bitmap, int pixels) { 
Bitmap roundCornerBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); 
Canvas canvas = new Canvas(roundCornerBitmap); 
int color = 0xff424242;//int color = 0xff424242; 
Paint paint = new Paint(); 
paint.setColor(color); 
//防止锯齿 
paint.setAntiAlias(true); 
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 
RectF rectF = new RectF(rect); 
float roundPx = pixels; 
//相当于清屏 
canvas.drawARGB(0, 0, 0, 0); 
//先画了一个带圆角的矩形 
canvas.drawRoundRect(rectF, roundPx, roundPx, paint); 
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 
//再把原来的bitmap画到现在的bitmap!!!注意这个理解 
canvas.drawBitmap(bitmap, rect, rect, paint); 
return roundCornerBitmap; 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值