Skip to content

Instantly share code, notes, and snippets.

@chimbori
Created August 8, 2018 01:13
Show Gist options
  • Save chimbori/98750ef9e98f5652f87939a266ca74e9 to your computer and use it in GitHub Desktop.
Save chimbori/98750ef9e98f5652f87939a266ca74e9 to your computer and use it in GitHub Desktop.
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
public class BitmapUtils {
private BitmapUtils() {
}
public static Bitmap padBitmap(Bitmap bitmap, int borderSize) {
Bitmap bmpWithBorder = Bitmap.createBitmap(
bitmap.getWidth() + borderSize * 2, bitmap.getHeight() + borderSize * 2, bitmap.getConfig());
Canvas canvas = new Canvas(bmpWithBorder);
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(bitmap, borderSize, borderSize, null);
return bmpWithBorder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment