【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
2015-01-28 18:06
501 查看
使用到的类:
android.support.v4.graphics.drawable.RoundedBitmapDrawable;
android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
对于不带图片,仅仅只是包含字母或者文字的圆形头像,联系人里也提供了一个
com.android.contacts.common.lettertiles.LetterTileDrawable
示例代码:
Bitmap
src =BitmapFactory.decodeResource(getResources(),R.drawable.temp_pic);
RoundedBitmapDrawable
roundedBitmapDrawable =RoundedBitmapDrawableFactory.create(context.getResources(),src);
//设置圆角半径
roundedBitmapDrawable.setCornerRadius(Math.max(src.getWidth(),src.getHeight())/2.0f);
imageView.setImageDrawable(roundedBitmapDrawable);
一、Drawable to Bitmap
1.
Drawable d
= xxx;
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
2.
public static
Bitmap convertDrawable2BitmapByCanvas(Drawable drawable) {
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
// canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
二、Bitmap to Drawable
Bitmap bm =
xxx;
BitmapDrawable bd = new BitmapDrawable(bm);
因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。
caed
相关文章:
http://www.csdn123.com/html/topnews201408/63/8763.htm
http://www.pocketdigi.com/20141101/1389.html
http://blog.sina.com.cn/s/blog_4607d856010125sl.html
android.support.v4.graphics.drawable.RoundedBitmapDrawable;
android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
对于不带图片,仅仅只是包含字母或者文字的圆形头像,联系人里也提供了一个
com.android.contacts.common.lettertiles.LetterTileDrawable
示例代码:
Bitmap
src =BitmapFactory.decodeResource(getResources(),R.drawable.temp_pic);
RoundedBitmapDrawable
roundedBitmapDrawable =RoundedBitmapDrawableFactory.create(context.getResources(),src);
//设置圆角半径
roundedBitmapDrawable.setCornerRadius(Math.max(src.getWidth(),src.getHeight())/2.0f);
imageView.setImageDrawable(roundedBitmapDrawable);
一、Drawable to Bitmap
1.
Drawable d
= xxx;
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
2.
public static
Bitmap convertDrawable2BitmapByCanvas(Drawable drawable) {
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
// canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
二、Bitmap to Drawable
Bitmap bm =
xxx;
BitmapDrawable bd = new BitmapDrawable(bm);
因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。
caed
相关文章:
http://www.csdn123.com/html/topnews201408/63/8763.htm
http://www.pocketdigi.com/20141101/1389.html
http://blog.sina.com.cn/s/blog_4607d856010125sl.html
相关文章推荐
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- 【Android】【Drawable】图片圆形化(RoundedBitmapDrawable)
- android RoundedBitmapDrawable最简单方式实现圆角图片(一)
- android图片缓存(包含ReusableBitmapDrawable和BitmapPool)
- Android如何缩放图片以及Drawable转Bitmap方法
- android 图片倒影 bitmap与drawable的转换 把图片处理成指定大小 图片圆角处理 dip转换成px
- Android图片二进制与Bitmap、Drawable之间的转换
- Android图片二进制与Bitmap、Drawable之间的转换
- Android Bitmap和Drawable互转及使用BitmapFactory解析图片流
- Android Drawable和Bitmap图片之间转换
- android 获取资源文件 R.drawable中的图片转换为drawable、bitmap(转载)
- android在处理图片资源的时候,Drawable、Bitmap、byte[]之间的转换
- [Android] bitmap/drawable/byte的转换和获取圆角/倒影图片
- Android图片操作-将Drawable转化为Bitmap
- Android Drawable和Bitmap图片之间转换