欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用RoundedBitmapDrawable生成圓角圖片的方法

 更新時(shí)間:2016年09月01日 11:39:13   作者:森林森  
由于RoundedBitmapDrawable類沒有直接提供生成圓形圖片的方法,所以生成圓形圖片首先需要對(duì)原始圖片進(jìn)行裁剪,將圖片裁剪成正方形,最后再生成圓形圖片,具體實(shí)現(xiàn)方法,可以參考下本文

Bitmap src = BitmapFactory.decodeResource(getResources(), imageId); //獲取Bitmap圖片
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), src); //創(chuàng)建RoundedBitmapDrawable對(duì)象
roundedBitmapDrawable.setCornerRadius(100); //設(shè)置圓角半徑(根據(jù)實(shí)際需求)
roundedBitmapDrawable.setAntiAlias(true); //設(shè)置反走樣
image.setImageDrawable(roundedBitmapDrawable); //顯示圓角圖片 

動(dòng)態(tài)

生成圓形圖片

由于RoundedBitmapDrawable類沒有直接提供生成圓形圖片的方法,所以生成圓形圖片首先需要對(duì)原始圖片進(jìn)行裁剪,將圖片裁剪成正方形,最后再生成圓形圖片,具體實(shí)現(xiàn)如下:

Bitmap src = BitmapFactory.decodeResource(getResources(), imageId);
Bitmap dst;
//將長(zhǎng)方形圖片裁剪成正方形圖片
if (src.getWidth() >= src.getHeight()){
dst = Bitmap.createBitmap(src, src.getWidth()/2 - src.getHeight()/2, 0, src.getHeight(), src.getHeight()
);
}else{
dst = Bitmap.createBitmap(src, 0, src.getHeight()/2 - src.getWidth()/2, src.getWidth(), src.getWidth()
);
}
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), dst);
roundedBitmapDrawable.setCornerRadius(dst.getWidth() / 2); //設(shè)置圓角半徑為正方形邊長(zhǎng)的一半
roundedBitmapDrawable.setAntiAlias(true);
image.setImageDrawable(roundedBitmapDrawable);

以上所述是小編給大家介紹的使用RoundedBitmapDrawable生成圓角圖片的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論