result = recycled; } else { result = Bitmap.createBitmap(width, height, getSafeConfig(toCrop));
/** * Rotate and/or flip the image to match the given exif orientation. * * @param toOrient The bitmap to rotate/flip. * @param pool A pool that may or may not contain an image of the necessary dimensions. * @param exifOrientation the exif orientation [1-8]. * @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary. */ public static Bitmap rotateImageExif(Bitmap toOrient, BitmapPool pool, int exifOrientation) { final Matrix matrix = new Matrix(); initializeMatrixForRotation(exifOrientation, matrix); if (matrix.isIdentity()) { return toOrient; } // From Bitmap.createBitmap. final RectF newRect = new RectF(0, 0, toOrient.getWidth(), toOrient.getHeight()); matrix.mapRect(newRect); final int newWidth = Math.round(newRect.width()); final int newHeight = Math.round(newRect.height()); Bitmap.Config config = getSafeConfig(toOrient); Bitmap result = pool.get(newWidth, newHeight, config); if (result == null) { result = Bitmap.createBitmap(newWidth, newHeight, config); } matrix.postTranslate(-newRect.left, -newRect.top); final Canvas canvas = new Canvas(result); final Paint paint = new Paint(PAINT_FLAGS); canvas.drawBitmap(toOrient, matrix, paint); return result; }
Bitmap.Config config = getSafeConfig(toFit); Bitmap toReuse = pool.get(targetWidth, targetHeight, config); if (toReuse == null) {
m.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f)); Bitmap result = pool.get(width, height, getSafeConfig(inBitmap));
targetHeight = (int) (minPercentage * inBitmap.getHeight()); Bitmap.Config config = getSafeConfig(inBitmap); Bitmap toReuse = pool.get(targetWidth, targetHeight, config);
/** * Rotate and/or flip the image to match the given exif orientation. * * @param pool A pool that may or may not contain an image of the necessary * dimensions. * @param inBitmap The bitmap to rotate/flip. * @param exifOrientation the exif orientation [1-8]. * @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary. */ public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int exifOrientation) { if (!isExifOrientationRequired(exifOrientation)) { return inBitmap; } final Matrix matrix = new Matrix(); initializeMatrixForRotation(exifOrientation, matrix); // From Bitmap.createBitmap. final RectF newRect = new RectF(0, 0, inBitmap.getWidth(), inBitmap.getHeight()); matrix.mapRect(newRect); final int newWidth = Math.round(newRect.width()); final int newHeight = Math.round(newRect.height()); Bitmap.Config config = getSafeConfig(inBitmap); Bitmap result = pool.get(newWidth, newHeight, config); matrix.postTranslate(-newRect.left, -newRect.top); applyMatrix(inBitmap, result, matrix); return result; }