Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends Activity {
- static ImageView imageView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- imageView=(ImageView)findViewById(R.id.imageView1);
- Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.images_1);
- imageView.setImageBitmap(getCircleBitmap(bitmap));
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- public static Bitmap getCircleBitmap(Bitmap bitmap) {
- //crop to circle
- Bitmap output;
- //check if its a rectangular image
- if (bitmap.getWidth() > bitmap.getHeight()) {
- output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
- } else {
- output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Config.ARGB_8888);
- }
- Canvas canvas = new Canvas(output);
- float r = 0;
- if (bitmap.getWidth() > bitmap.getHeight()) {
- r = bitmap.getHeight() / 2;
- } else {
- r = bitmap.getWidth() / 2;
- }
- final Paint paint = new Paint();
- final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
- paint.setColor(Color.WHITE);
- paint.setAntiAlias(true);
- canvas.drawARGB(0, 0, 0, 0);
- canvas.drawCircle(r, r, r, paint);
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
- canvas.drawBitmap(bitmap, rect, rect, paint);
- Rect bounds = new Rect();
- int x = (bitmap.getWidth() - bounds.width())/2;
- int y = (bitmap.getHeight() + bounds.height())/2;
- canvas.drawText("hii",x,y, paint);
- return output;
- }
- <ImageView
- android:id="@+id/imageView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView1"
- android:layout_below="@+id/textView1"
- android:layout_marginLeft="26dp"
- android:layout_marginTop="52dp"
- android:src="@drawable/image" />
- <?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="fill_parent"
- android:layout_height="fill_parent" >
- <ImageView
- android:id="@+id/flag"
- android:layout_width="fill_parent"
- android:layout_height="250dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:scaleType="fitXY"
- android:src="@drawable/ic_launcher" />
- <TextView
- android:id="@+id/textview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_marginTop="20dp"
- android:layout_centerHorizontal="true" />
- </RelativeLayout>
- android:drawableTop=""
- android:drawableBottom=""
- android:drawableLeft=""
- android:drawableRight=""
- android:drawableStart=""
- android:drawableEnd=""
- android:drawablePadding=""
- TextView.setText(yourtext);
- imageview.setImageBitmap(yourbitmapobject);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement