List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts)
From source file:Main.java
public static Bitmap decodeSampledBitmapFromData(byte[] data) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/* ww w . j a v a 2 s . com*/ BitmapFactory.decodeByteArray(data, 0, data.length, options); options.inSampleSize = 1; // saved image will be one half the width and // height of the original (image captured is // double the resolution of the screen size) // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(data, 0, data.length, options); }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromFile(byte[] data, int reqWidth, int reqHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); // First decode with inJustDecodeBounds=true to check dimensions options.inJustDecodeBounds = true;//from www . ja va 2s.c o m BitmapFactory.decodeByteArray(data, 0, data.length, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(data, 0, data.length, options); }
From source file:Main.java
public static Bitmap toBitmap(String s) { //byte[] Buffer = s.getBytes(); byte[] buffer = Base64.decode(s, Base64.DEFAULT); //ByteArrayInputStream inputStream = new ByteArrayInputStream(Buffer); //Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return BitmapFactory.decodeByteArray(buffer, 0, buffer.length, null); }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromByteArray(byte[] bytes, long allowedBmpMaxMemorySize) { try {/* w ww . j a v a 2 s .c o m*/ final Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); options.inSampleSize = calculateInSampleSize(options, allowedBmpMaxMemorySize); options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); } catch (Throwable err) { err.printStackTrace(); } return null; }
From source file:Main.java
public static Bitmap decodeBitmapFromResource(byte[] byteArray, int reqWidth) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//w w w. ja v a 2 s .c om BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, options); }
From source file:Main.java
public static Bitmap Bytes2Bimap(byte[] bytes, int maxSize) { try {//from w w w .ja v a2s . co m if (bytes == null) { return null; } if (bytes.length != 0) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opt); int scale = 1; if ((opt.outHeight > maxSize) || (opt.outWidth > maxSize)) { scale = (int) Math.pow(2, (int) Math.round( Math.log(maxSize / (double) Math.max(opt.outHeight, opt.outWidth)) / Math.log(0.5))); } BitmapFactory.Options newOpt = new BitmapFactory.Options(); newOpt.inSampleSize = scale; return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, newOpt); } else { return null; } } catch (Exception ex) { return null; } }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromResource(byte[] imageData, 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 a 2s.com*/ BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options); }
From source file:Main.java
public static Bitmap loadBitmap(byte[] bytes, int width, int height) { BitmapFactory.Options options = new BitmapFactory.Options(); //only load bound information? bound information is regarding property of the picture options.inJustDecodeBounds = true;/*from w w w. j a va2 s . c o m*/ BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); //to get the picture's original width and height int w = options.outWidth / width; int h = options.outHeight / height; int scale = w > h ? w : h; options.inSampleSize = scale; options.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); }
From source file:Main.java
public static Bitmap decodeByteArray(byte[] data) { try {/*w w w .j av a2 s . c om*/ if (data == null) { return null; } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(data, 0, data.length, options); options.inJustDecodeBounds = false; int be = (int) (options.outWidth / (float) ZEN_IMAGE_WIDTH); if (be <= 0) { be = 1; } options.inSampleSize = be; Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Bitmap decodePixelDeteriorationBitmapFromByteArray(byte[] byteArray, 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 v a 2 s. c o m*/ BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; // 2 bytes per pixel, not 4 options.inDither = true; return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, options); }