Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. public class MainActivity extends Activity {
  2.  
  3. static ImageView imageView;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9.  
  10. imageView=(ImageView)findViewById(R.id.imageView1);
  11.  
  12. Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.images_1);
  13. imageView.setImageBitmap(getCircleBitmap(bitmap));
  14.  
  15. }
  16.  
  17. @Override
  18. public boolean onCreateOptionsMenu(Menu menu) {
  19. // Inflate the menu; this adds items to the action bar if it is present.
  20. getMenuInflater().inflate(R.menu.main, menu);
  21. return true;
  22. }
  23.  
  24.  
  25. public static Bitmap getCircleBitmap(Bitmap bitmap) {
  26.  
  27. //crop to circle
  28. Bitmap output;
  29. //check if its a rectangular image
  30. if (bitmap.getWidth() > bitmap.getHeight()) {
  31. output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
  32. } else {
  33. output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Config.ARGB_8888);
  34. }
  35. Canvas canvas = new Canvas(output);
  36.  
  37. float r = 0;
  38.  
  39. if (bitmap.getWidth() > bitmap.getHeight()) {
  40. r = bitmap.getHeight() / 2;
  41. } else {
  42. r = bitmap.getWidth() / 2;
  43. }
  44.  
  45. final Paint paint = new Paint();
  46. final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
  47.  
  48. paint.setColor(Color.WHITE);
  49.  
  50. paint.setAntiAlias(true);
  51. canvas.drawARGB(0, 0, 0, 0);
  52.  
  53. canvas.drawCircle(r, r, r, paint);
  54. paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  55. canvas.drawBitmap(bitmap, rect, rect, paint);
  56.  
  57. Rect bounds = new Rect();
  58. int x = (bitmap.getWidth() - bounds.width())/2;
  59. int y = (bitmap.getHeight() + bounds.height())/2;
  60.  
  61. canvas.drawText("hii",x,y, paint);
  62.  
  63. return output;
  64. }
  65.  
  66. <ImageView
  67. android:id="@+id/imageView1"
  68. android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"
  70. android:layout_alignLeft="@+id/textView1"
  71. android:layout_below="@+id/textView1"
  72. android:layout_marginLeft="26dp"
  73. android:layout_marginTop="52dp"
  74. android:src="@drawable/image" />
  75.  
  76. <?xml version="1.0" encoding="utf-8"?>
  77. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  78. xmlns:tools="http://schemas.android.com/tools"
  79. android:layout_width="fill_parent"
  80. android:layout_height="fill_parent" >
  81.  
  82. <ImageView
  83. android:id="@+id/flag"
  84. android:layout_width="fill_parent"
  85. android:layout_height="250dp"
  86. android:layout_alignParentLeft="true"
  87. android:layout_alignParentRight="true"
  88. android:scaleType="fitXY"
  89. android:src="@drawable/ic_launcher" />
  90.  
  91. <TextView
  92. android:id="@+id/textview"
  93. android:layout_width="wrap_content"
  94. android:layout_height="wrap_content"
  95. android:layout_alignParentTop="true"
  96. android:layout_marginTop="20dp"
  97. android:layout_centerHorizontal="true" />
  98.  
  99. </RelativeLayout>
  100.  
  101. android:drawableTop=""
  102. android:drawableBottom=""
  103. android:drawableLeft=""
  104. android:drawableRight=""
  105. android:drawableStart=""
  106. android:drawableEnd=""
  107. android:drawablePadding=""
  108.  
  109. TextView.setText(yourtext);
  110. imageview.setImageBitmap(yourbitmapobject);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement