List of usage examples for android.graphics BitmapFactory decodeStream
@Nullable public static Bitmap decodeStream(@Nullable InputStream is, @Nullable Rect outPadding, @Nullable Options opts)
From source file:Main.java
private static Bitmap getBitmap(Context paramContext, int paramInt) { BitmapFactory.Options localOptions = new BitmapFactory.Options(); Bitmap.Config localConfig = Bitmap.Config.RGB_565; localOptions.inPreferredConfig = localConfig; return BitmapFactory.decodeStream(paramContext.getResources().openRawResource(paramInt), null, localOptions);// w w w. jav a 2 s. com }
From source file:Main.java
public static Bitmap decodeFile(File f) { try {//from w w w .j a v a2s.c om BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f), null, o); final int REQUIRED_SIZE = 70; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale++; } BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) { } return null; }
From source file:Main.java
public static Bitmap decodeImageFile(File f) { try {//from w w w . j av a2 s . c o m //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f), null, o); //The new size we want to scale to final int REQUIRED_SIZE = 70; //Find the correct scale value. It should be the power of 2. int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale *= 2; } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) { } return null; }
From source file:Main.java
public static Bitmap decodeInputStream(InputStream is) { try {/*from www . j ava2 s . c om*/ BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, options); options.inJustDecodeBounds = false; int be = (int) (options.outWidth / (float) ZEN_IMAGE_WIDTH); if (be <= 0) { be = 1; } options.inSampleSize = be; Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static final Bitmap getBitmapFromRaw(Context context, int resId) { if (resId <= 0) return null; try {/* ww w . j a v a2s. c o m*/ InputStream is = context.getResources().openRawResource(resId); BitmapFactory.Options imageOptions = new BitmapFactory.Options(); Bitmap bmp = BitmapFactory.decodeStream(is, null, imageOptions); return bmp; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromInputStream(InputStream stream, 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 av a2s. c o m*/ options.inPurgeable = true; BitmapFactory.decodeStream(stream, null, options); if (options.outHeight > 0 && options.outWidth > 0) { // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeStream(stream, null, options); } else { return null; } }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromResource(InputStream is, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from ww w .j av a 2s . c om*/ //BitmapFactory.decodeResource(res, resId, options); BitmapFactory.decodeStream(is, null, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeStream(is, null, options); // return BitmapFactory.decodeResource(res, resId, options); }
From source file:Main.java
public static Bitmap decodeFile(File f, int maxSize) { Bitmap b = null;//from w w w . j a v a 2 s. c o m try { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > maxSize || o.outWidth > maxSize) { scale = (int) Math.pow(2, (int) Math .round(Math.log(maxSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return b; }
From source file:Main.java
public static Bitmap generateBitmap(Context context, int resId, BitmapFactory.Options options) { options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true;//from w ww . j a v a 2s. c o m options.inInputShareable = true; InputStream is = context.getResources().openRawResource(resId); return BitmapFactory.decodeStream(is, null, options); }
From source file:Main.java
public static Bitmap revitionImageSize(String path) throws IOException { BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path))); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//w w w . j av a 2 s .c o m BitmapFactory.decodeStream(in, null, options); in.close(); int i = 0; Bitmap bitmap = null; while (true) { if ((options.outWidth >> i <= 1000) && (options.outHeight >> i <= 1000)) { in = new BufferedInputStream(new FileInputStream(new File(path))); options.inSampleSize = (int) Math.pow(2.0D, i); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeStream(in, null, options); break; } i += 1; } return bitmap; }