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にも使えない。
個人的には使うことなさそうかな。。。
