/** * Sets a Bitmap and initializes the image rotation according to the EXIT data.<br> * <br> * The EXIF can be retrieved by doing the following: <code> * ExifInterface exif = new ExifInterface(path);</code> * * @param bitmap the original bitmap to set; if null, this * @param exif the EXIF information about this bitmap; may be null */ public void setImageBitmap(Bitmap bitmap, ExifInterface exif) { if (bitmap != null && exif != null) { ImageViewUtil.RotateBitmapResult result = ImageViewUtil.rotateBitmapByExif(bitmap, exif); bitmap = result.bitmap; mDegreesRotated = result.degrees; } setImageBitmap(bitmap); }
/** * Sets a bitmap loaded from the given Android URI as the content of the CropImageView.<br> * Can be used with URI from gallery or camera source.<br> * Will rotate the image by exif data.<br> * * @param uri the URI to load the image from */ public void setImageUri(Uri uri) { if (uri != null) { DisplayMetrics metrics = getResources().getDisplayMetrics(); double densityAdj = metrics.density > 1 ? 1 / metrics.density : 1; int width = (int) (metrics.widthPixels * densityAdj); int height = (int) (metrics.heightPixels * densityAdj); ImageViewUtil.DecodeBitmapResult decodeResult = ImageViewUtil.decodeSampledBitmap(getContext(), uri, width, height); ImageViewUtil.RotateBitmapResult rotateResult = ImageViewUtil.rotateBitmapByExif(getContext(), decodeResult.bitmap, uri); setImageBitmap(rotateResult.bitmap); mLoadedImageUri = uri; mLoadedSampleSize = decodeResult.sampleSize; mDegreesRotated = rotateResult.degrees; } }