title: Out of memory during working with Bitmap in android
body: <p>I use the method quoted below to round the corners of any bitmap. Some time it works perfectly, some time not because of OutOfMemory exception. The exception often occur at the line </p>
  
  <pre><code>Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
          bitmap.getHeight(), Config.ARGB_8888);
  </code></pre>
  
  <p>Do I miss any special codes here? Please help me.</p>
  
  <pre><code> public static Bitmap roundBitmap(Bitmap bitmap, int roundedRadius) {
      if (bitmap == null)
          return null;
      if (roundedRadius == 0) {
          return bitmap;
      }
      // Bitmap output = bitmap.copy(Config.ARGB_8888, true);
      Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
              bitmap.getHeight(), Config.ARGB_8888);
      Canvas canvas = new Canvas(output);
      final int color = 0xffffff00;
      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 = roundedRadius;
  
      paint.setAntiAlias(true);
      canvas.drawARGB(0, 0, 0, 0);
      paint.setColor(color);
      canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
  
      paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
      canvas.drawBitmap(bitmap, rect, rect, paint);
      return output;
  }
  </code></pre>