Android Utililty Methods Bitmap Decode

List of utility methods to do Bitmap Decode

Description

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

Method

BitmapdecodeBitmap(String path, int displayWidth, int displayHeight)
get a bitamp can center inside the rect of displayWidth * displayHeight
BitmapFactory.Options op = new BitmapFactory.Options();
op.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(path, op);
int wRatio = (int) Math.ceil(op.outWidth / (float) displayWidth);
int hRatio = (int) Math.ceil(op.outHeight / (float) displayHeight);
if (wRatio > 1 && hRatio > 1) {
    if (wRatio > hRatio) {
        op.inSampleSize = wRatio;
...
BitmapdecodeBitmap(String path, int maxImageSize)
decode Bitmap
BitmapFactory.Options op = new BitmapFactory.Options();
op.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(path, op);
int scale = 1;
if (op.outWidth > maxImageSize || op.outHeight > maxImageSize) {
    scale = (int) Math.pow(
            2,
            (int) Math.round(Math.log(maxImageSize
...
BitmapdecodeSampledBitmapFromFile(String filename, int reqWidth, int reqHeight)
decode Sampled Bitmap From File
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filename, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
        reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(filename, options);
BitmapdecodeSampledBitmap(Uri uri, int reqWidth, int reqHeight, Activity act)
decode Sampled Bitmap
InputStream is;
try {
    is = act.getApplicationContext().getContentResolver()
            .openInputStream(uri);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(is, null, options);
    is.close(); 
...
BitmapdecodeBitmapFromAssets(Context context, String fileName)
decode Bitmap From Assets
InputStream is = null;
try {
    is = context.getAssets().open(fileName);
    return BitmapFactory.decodeStream(is);
} catch (Exception e) {
    return null;
} finally {
    if (is != null) {
...
BitmapdecodeImageFile(String strImagePath, BitmapFactory.Options options, boolean checkOrientation)
decode Image File
if (checkOrientation == false) {
    return BitmapFactory.decodeFile(strImagePath, options);
} else {
    Bitmap bm = BitmapFactory.decodeFile(strImagePath, options);
    int degree = getExifDegree(strImagePath);
    return getRotatedBitmap(bm, degree);
BitmapdecodeSampledBitmapFromByte(byte[] res, int reqWidth, int reqHeight)
decode Sampled Bitmap From Byte
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
    BitmapFactory.decodeByteArray(res, 0, res.length, options);
} catch (OutOfMemoryError e) {
    return null;
options.inSampleSize = calculateInSampleSize(options, reqWidth,
...
BitmapdecodeSampledBitmapFromFile(String file, int reqWidth, int reqHeight)
decode Sampled Bitmap From File
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
        reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(file, options);
BitmapdecodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight)
decode Sampled Bitmap From Resource
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
        reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);