Android Support Library v4にあるRoundedBitmapDrawable
を使えば、
RoundedImageViewやUniversal Image Loaderなど多数あるライブラリを使用せずに角丸画像の表示ができます。
RoundedBitmapDrawableのインスタンス生成
RoundedBitmapDrawableFactory
の以下のいずれかのメソッドを使用して、インスタンスを生成して使用します。
RoundedBitmapDrawableFactory#create
public static RoundedBitmapDrawable create(Resources res, Bitmap bitmap)
public static RoundedBitmapDrawable create(Resources res, String filepath)
public static RoundedBitmapDrawable create(Resources res, InputStream is) {
引数はBitmap
、ファイル名、InputStream
のいずれかなので、
ネットワーク上の画像、端末内のファイル、Assets、Rawリソースなどに使えます。
(あまり用途はないかもしれないけど)Drawableリソースの場合は以下の通り、少し面倒。
URLではなく、ファイル名なのでこの方法ではできませんでした。
BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.xxx);
Bitmap bitmap = bitmapDrawable.getBitmap();
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
drawable.setCornerRadius(100);
imageView.setImageDrawable(drawable);
結論
XMLでも書けないし、RoundedBitmapDrawable
から変換後のBitmap
が取れるわけでもないので、Picasso
のTransformation
にも使えない。
個人的には使うことなさそうかな。。。