1.添加一个ImgaView。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="Hello World!" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/test" />
</RelativeLayout>
2.编写修改bitmap的函数
private RoundedBitmapDrawable rectRoundBitmap(Bitmap bitmap){
//创建RoundedBitmapDrawable对象
RoundedBitmapDrawable roundImg = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
//抗锯齿
roundImg.setAntiAlias(true);
//设置圆角半径
roundImg.setCornerRadius(15);
return roundImg;
}
3.显示修改完后的bitmap
ImageView im=(ImageView)findViewById(R.id.imageView);
Bitmap image= BitmapFactory.decodeResource(getResources(), R.drawable.test);
im.setImageDrawable( rectRoundBitmap(image));
4.效果图