Android Utililty Methods Bitmap Resize

List of utility methods to do Bitmap Resize

Description

The list of methods to do Bitmap Resize are organized into topic(s).

Method

intcalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
calculate In Sample Size
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
    if (width > height)
        inSampleSize = Math.round((float) height
                / (float) reqHeight);
    else
...
intcalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
calculate In Sample Size
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
    final int heightRatio = Math.round((float) height
            / (float) reqHeight);
    final int widthRatio = Math.round((float) width
            / (float) reqWidth);
...
BitmapcreateFitCenterBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
create Fit Center Bitmap
if (srcBitmap == null || dstWidth <= 0 || dstHeight <= 0) {
    return srcBitmap;
int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();
int newWidth = srcWidth;
int newHeight = srcHeight;
if (newWidth > dstWidth) {
...
BitmapcreateFitXYBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
create Fit XY Bitmap
if (srcBitmap == null || dstWidth <= 0 || dstHeight <= 0) {
    return srcBitmap;
Bitmap dstBitmap = srcBitmap;
try {
    dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth,
            dstHeight, true);
    if (dstBitmap != srcBitmap && tryRecycleSource) {
...
BitmapgetSampledBitmap(String filePath, int reqWidth, int reqHeight)
get Sampled Bitmap
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
    if (width > height) {
...
BitmapmanageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation)
manage Bitmap Rotatio
Bitmap rotateBitmap = bitMap;
switch (rotation) {
case ExifInterface.ORIENTATION_UNDEFINED:
    break;
case ExifInterface.ORIENTATION_NORMAL:
    break;
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
    break;
...
BitmapreadBitmapAutoSize(String filePath, int outWidth, int outHeight)
read Bitmap Auto Size
FileInputStream fs = null;
BufferedInputStream bs = null;
try {
    fs = new FileInputStream(filePath);
    bs = new BufferedInputStream(fs);
    BitmapFactory.Options options = setBitmapOption(filePath,
            outWidth, outHeight);
    return BitmapFactory.decodeStream(bs, null, options);
...
Bitmapresize(Bitmap bitmap, int newWidth, int newHeight)
Resize.
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, newWidth,
        newHeight);
return resizedBitmap;
BitmapresizeAndCropCenter(Bitmap bitmap, int size, boolean recycle)
resize And Crop Center
int w = bitmap.getWidth();
int h = bitmap.getHeight();
if (w == size && h == size)
    return bitmap;
float scale = (float) size / Math.min(w, h);
Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
int width = Math.round(scale * bitmap.getWidth());
int height = Math.round(scale * bitmap.getHeight());
...
BitmapresizeAndCropCenter(final Bitmap bitmap, final int size)
This is only used when the launcher shortcut is created.
final int w = bitmap.getWidth();
final int h = bitmap.getHeight();
if (w == size && h == size) {
    return bitmap;
final float mScale = (float) size / Math.min(w, h);
final Bitmap mTarget = Bitmap.createBitmap(size, size,
        Bitmap.Config.ARGB_8888);
...