Modify Bitmap To have Rounded White Corners
<p>This is related to the <a href="http://stackoverflow.com/questions/13822436/storing-a-modified-bitmap-to-disk/13823288#13823288">last question</a> I asked. Basically I want to store a bitmap on disk with rounded corners. The last question was solved by modifying the image to have transparent corners and then save this as a PNG. The problem with this is that saving and retrieving a PNG is a lot slower than a JPEG. Obviously it is not possible to store the transparent corners in a JPEG format.</p>

<p>My next idea was to make the corners white. This would work as the layout around and behind the photo is white. So it would appear transparent but I am still able to save the image as JPEG and reap the rewards in performance of my list view. The only problem is I cannot figure out how to create the rounded white corners. Here is the base of what I am working with..</p>

<pre><code>private Paint paint = new Paint();
private Canvas canvas;
private Rect rect;
private RectF rectF;
private Bitmap output;

@Inject
public ImageRounder() {}

public synchronized Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
            .getHeight(), Bitmap.Config.ARGB_8888);
    canvas = new Canvas(output);
    paint.reset();
    canvas.drawColor(Color.WHITE);
    rect =  new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    rectF = new RectF(rect);
    float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.WHITE);

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;

}
</code></pre>
