title: Rounded top corners of bitmap android
body: <p>I am using this code to get top rounded corners of bitmap</p>
  
  <pre><code>public static void setTopRounded(Bitmap workingBitmap , int w, int h, ImageView v,Context context)
  {
      Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(bmp);
      Shader shader = new BitmapShader(workingBitmap, Shader.TileMode.MIRROR,
              Shader.TileMode.MIRROR);
  
      Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
      paint.setAntiAlias(true);
      paint.setShader(shader);
      RectF rec = new RectF(0, 0, w, h - 20);
      c.drawRect(new RectF(0, 20, w, h), paint);
      c.drawRoundRect(rec, 10, 10, paint);
      v.setBackgroundDrawable(new BitmapDrawable(context.getResources(), bmp));
  }
  </code></pre>
  
  <p>and my XML code for Image view is</p>
  
  <pre><code>&lt;ImageView 
      android:layout_height="140dp"
      android:layout_width="match_parent"
      android:id="@+id/profileIV"
      android:visibility="gone"
      android:scaleType="centerCrop" /&gt;
  </code></pre>
  
  <p>now the problem is by setting </p>
  
  <p><code>v.setBackgroundDrawable(new BitmapDrawable(context.getResources(), bmp))</code>, 
  <code>android:scaleType="centerCrop"</code></p>
  
  <p>property did not work and if i use</p>
  
  <p><code>v.setImageDrawable(new BitmapDrawable(context.getResources(), bmp))</code> </p>
  
  <p>then scale type works but the image does not get rounded.
  What i am doing wrong?</p>