List of utility methods to do Bitmap Decode
Bitmap | decodeBitmap(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; ... |
Bitmap | decodeBitmap(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 ... |
Bitmap | decodeSampledBitmapFromFile(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); |
Bitmap | decodeSampledBitmap(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(); ... |
Bitmap | decodeBitmapFromAssets(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) { ... |
Bitmap | decodeImageFile(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); |
Bitmap | decodeSampledBitmapFromByte(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, ... |
Bitmap | decodeSampledBitmapFromFile(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); |
Bitmap | decodeSampledBitmapFromResource(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); |