Android rounded corner image,
Android rounded corner Image
Import android. app. Activity;
Import android. app. AlertDialog;
Import android. content. BroadcastReceiver;
Import android. content. Context;
Import android. content. DialogInterface;
Import android. content. Intent;
Import android. content. IntentFilter;
Import android. content. SharedPreferences;
Import android. content. SharedPreferences. Editor;
Import android. graphics. Bitmap;
Import android. graphics. Bitmap. Config;
Import android. graphics. Canvas;
Import android. graphics. Paint;
Import android. graphics. PorterDuff. Mode;
Import android. graphics. porterduduxfermode;
Import android. graphics. Rect;
Import android. graphics. RectF;
Import android. graphics. drawable. BitmapDrawable;
Import android. graphics. drawable. Drawable;
Import android. OS. Bundle;
Import android. telephony. TelephonyManager;
Import android. view. KeyEvent;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. ImageView;
Import android. widget. Toast;
Public class MainActivity extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Yuanjiaotupian ();
}
Private void yuanjiaotupian (){
// TODO Auto-generated method stub
ImageView iv = (ImageView) findViewById (R. id. iv_main_yuanjiao );
Drawable drawable = getResources (). getDrawable (R. drawable. asd );
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable. getBitmap ();
BitmapDrawable bd = new BitmapDrawable (toRoundCorner (bitmap, 30 ));
Iv. setBackgroundDrawable (bd );
}
/**
* Method for obtaining the rounded corner bitmap
*
* @ Param bitmap
* Bitmap to be converted to rounded corner
* @ Param pixels
* The degree of the rounded corner. The larger the value, the larger the rounded corner.
* @ Return refers to the rounded corner bitmap after processing.
*/
Public static Bitmap toRoundCorner (Bitmap bitmap, int pixels ){
Bitmap output = Bitmap. createBitmap (bitmap. getWidth (),
Bitmap. getHeight (), Config. ARGB_8888 );
Canvas canvas = new Canvas (output );
Final int color = 0xff0000242;
Final Paint paint = new Paint ();
Final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight ());
Final RectF rectF = new RectF (rect );
Final float roundPx = pixels;
Paint. setAntiAlias (true );
Canvas. drawARGB (0, 0, 0, 0 );
Paint. setColor (color );
Canvas. drawRoundRect (rectF, roundPx, roundPx, paint );
Paint. setXfermode (new porterduxfermode (Mode. SRC_IN ));
Canvas. drawBitmap (bitmap, rect, rect, paint );
Return output;
}
}