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

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

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

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

動態(tài)

生成圓形圖片

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

Bitmap src = BitmapFactory.decodeResource(getResources(), imageId);
Bitmap dst;
//將長方形圖片裁剪成正方形圖片
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); //設置圓角半徑為正方形邊長的一半
roundedBitmapDrawable.setAntiAlias(true);
image.setImageDrawable(roundedBitmapDrawable);

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

您可能感興趣的文章:

相關文章

最新評論