List of usage examples for android.graphics BitmapRegionDecoder newInstance
public static BitmapRegionDecoder newInstance(byte[] data, int offset, int length, boolean isShareable) throws IOException
From source file:Main.java
public static Bitmap decodeByteArray(byte[] buffer, int reqWidth, int reqHeight) { BitmapFactory.Options opts = new BitmapFactory.Options(); // Determine insample size opts.inJustDecodeBounds = true;//from w w w . j ava2s .co m BitmapFactory.decodeByteArray(buffer, 0, buffer.length, opts); opts.inSampleSize = calculateInSampleSize(opts, reqWidth, reqHeight); // Decode the bitmap, regionally if necessary Bitmap bitmap = null; opts.inJustDecodeBounds = false; Rect rect = getCropRectIfNecessary(opts, reqWidth, reqHeight); try { if (rect != null) { BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(buffer, 0, buffer.length, false); bitmap = decoder.decodeRegion(rect, opts); } else { bitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.length, opts); } } catch (IOException e) { Log.e(TAG, "Unable to decode bitmap from stream", e); } return bitmap; }