List of usage examples for android.graphics BitmapFactory decodeFile
public static Bitmap decodeFile(String pathName, Options opts)
From source file:Main.java
public static Bitmap decodeSampledBitmap(String file, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w .j ava2 s.c om BitmapFactory.decodeFile(file, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(file, options); }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromPath(String pathName, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w . j a v a2 s .c o m BitmapFactory.decodeFile(pathName, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(pathName, options); }
From source file:Main.java
public static void setImageSrc(ImageView imageView, String imagePath) { BitmapFactory.Options option = new BitmapFactory.Options(); option.inSampleSize = getImageScale(imagePath); Bitmap bm = BitmapFactory.decodeFile(imagePath, option); imageView.setImageBitmap(bm);/*from w w w . j ava 2s .c om*/ }
From source file:Main.java
public static Bitmap getPic(File file, int width, int height) { String uri = file.getAbsolutePath(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(uri, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / width, photoH / height); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true;//w w w.j a va2 s . c o m return BitmapFactory.decodeFile(uri, bmOptions); }
From source file:Main.java
public static Bitmap compressPixel1(String imgPath, float pixelW, float pixelH) { BitmapFactory.Options newOpts = new BitmapFactory.Options(); newOpts.inJustDecodeBounds = true;/*from w ww. j a v a 2s . c o m*/ newOpts.inPreferredConfig = Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeFile(imgPath, newOpts); newOpts.inJustDecodeBounds = false; int w = newOpts.outWidth; int h = newOpts.outHeight; float hh = pixelH; float ww = pixelW; int height = h; int width = w; int inSampleSize = 1; if (h > hh || w > ww) { final int halfHeight = h / 2; final int halfWidth = w / 2; while ((halfHeight / inSampleSize) > hh && (halfWidth / inSampleSize) > ww) { inSampleSize *= 2; } if (h > w) { height = 1280; width = (1280 * w) / h; } else { width = 1280; height = (1280 * h) / w; } } newOpts.inSampleSize = inSampleSize; bitmap = BitmapFactory.decodeFile(imgPath, newOpts); Bitmap dst = Bitmap.createScaledBitmap(bitmap, width, height, false); if (bitmap != dst) { bitmap.recycle(); } return dst; }
From source file:Main.java
public static String getMimeTypeOfFile(String pathName) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true;//from www . j a v a 2 s. c o m BitmapFactory.decodeFile(pathName, opt); return opt.outMimeType; }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromFile(String file, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w . ja v a 2 s . c o m*/ BitmapFactory.decodeFile(file, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(file, options); }
From source file:Main.java
private static WeakReference<Bitmap> cprsBmpBySize(String path, int rqsW, int rqsH) { if (TextUtils.isEmpty(path)) return null; final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w . j a va 2 s . c o m BitmapFactory.decodeFile(path, options); options.inSampleSize = caculateInSampleSize(options, rqsW, rqsH); options.inJustDecodeBounds = false; return new WeakReference<Bitmap>(BitmapFactory.decodeFile(path, options)); }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromFile(String pathFile, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;// w w w.j a va 2 s . com BitmapFactory.decodeFile(pathFile, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(pathFile, options); }
From source file:Main.java
public static Bitmap decodeBitmapFromPath(String srcPath, int reqWidth, int reqHeight) { // First decode with <code>inJustDecodeBounds = true</code> to check dimensions. final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w . j av a2 s .c o m BitmapFactory.decodeFile(srcPath, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(srcPath, options); }