-
public class CropImageHelper to simplify crop image work like starting pick-image acitvity and handling camera/gallery intents.<br></br> The goal of the helper is to simplify the starting and most-common usage of image cropping and not all porpose all possible scenario one-to-rule-them-all code base. So feel free to use it as is and as a wiki to make your own.<br></br> Added value you get out-of-the-box is some edge case handling that you may miss otherwise, like the stupid-ass Android camera result URI that may differ from version to version and from device to device.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classCropImage.ActivityResultResult data of Crop Image Activity.
public classCropImage.CancelledResult
-
Field Summary
Fields Modifier and Type Field Description private final StringCROP_IMAGE_EXTRA_SOURCEprivate final StringCROP_IMAGE_EXTRA_OPTIONSprivate final StringCROP_IMAGE_EXTRA_BUNDLEprivate final StringCROP_IMAGE_EXTRA_RESULTprivate final IntegerPICK_IMAGE_CHOOSER_REQUEST_CODEprivate final IntegerPICK_IMAGE_PERMISSIONS_REQUEST_CODEprivate final IntegerCAMERA_CAPTURE_PERMISSIONS_REQUEST_CODEprivate final IntegerCROP_IMAGE_ACTIVITY_REQUEST_CODEprivate final IntegerCROP_IMAGE_ACTIVITY_RESULT_ERROR_CODEpublic final static CropImageINSTANCE
-
Method Summary
Modifier and Type Method Description final BitmaptoOvalBitmap(Bitmap bitmap)Create a new bitmap that has all pixels beyond the oval shape transparent. final UrigetCaptureImageOutputUriContent(Context context)Get URI to image received from capture by camera. final StringgetCaptureImageOutputUriFilePath(Context context, Boolean uniqueName)Get File Path to image received from capture by camera. final static UrigetPickImageResultUriContent(Context context, Intent data)Get the URI of the selected image Will return the correct URI for camera and gallery image. final static StringgetPickImageResultUriFilePath(Context context, Intent data, Boolean uniqueName)Get the File Path of the selected image final StringgetCROP_IMAGE_EXTRA_SOURCE()The key used to pass crop image source URI to CropImageActivity. final StringgetCROP_IMAGE_EXTRA_OPTIONS()The key used to pass crop image options to CropImageActivity. final StringgetCROP_IMAGE_EXTRA_BUNDLE()The key used to pass crop image bundle data to CropImageActivity. final StringgetCROP_IMAGE_EXTRA_RESULT()The key used to pass crop image result data back from CropImageActivity. final IntegergetPICK_IMAGE_CHOOSER_REQUEST_CODE()The request code used to start pick image activity to be used on result to identify the this specific request. final IntegergetPICK_IMAGE_PERMISSIONS_REQUEST_CODE()The request code used to request permission to pick image from external storage. final IntegergetCAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE()The request code used to request permission to capture image from camera. final IntegergetCROP_IMAGE_ACTIVITY_REQUEST_CODE()The request code used to start CropImageActivity to be used on result to identify the this specific request. final IntegergetCROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE()The result code used to return error from CropImageActivity. -
-
Method Detail
-
toOvalBitmap
final Bitmap toOvalBitmap(Bitmap bitmap)
Create a new bitmap that has all pixels beyond the oval shape transparent. Old bitmap is recycled.
-
getCaptureImageOutputUriContent
final Uri getCaptureImageOutputUriContent(Context context)
Get URI to image received from capture by camera.
This is not the File Path, for it please use getCaptureImageOutputUriFilePath
- Parameters:
context- used to access Android APIs, like content resolve, it is your activity/fragment/widget.
-
getCaptureImageOutputUriFilePath
final String getCaptureImageOutputUriFilePath(Context context, Boolean uniqueName)
Get File Path to image received from capture by camera.
- Parameters:
context- used to access Android APIs, like content resolve, it is your activity/fragment/widget.uniqueName- If true, make each image cropped have a different file name, this could cause memory issues, use wisely.
-
getPickImageResultUriContent
final static Uri getPickImageResultUriContent(Context context, Intent data)
Get the URI of the selected image Will return the correct URI for camera and gallery image.
This is not the File Path, for it please use getPickImageResultUriFilePath
- Parameters:
context- used to access Android APIs, like content resolve, it is your activity/fragment/widget.data- the returned data of the activity result
-
getPickImageResultUriFilePath
final static String getPickImageResultUriFilePath(Context context, Intent data, Boolean uniqueName)
Get the File Path of the selected image
- Parameters:
context- used to access Android APIs, like content resolve, it is your activity/fragment/widget.data- the returned data of the activity resultuniqueName- If true, make each image cropped have a different file name, this could cause memory issues, use wisely.
-
getCROP_IMAGE_EXTRA_SOURCE
final String getCROP_IMAGE_EXTRA_SOURCE()
The key used to pass crop image source URI to CropImageActivity.
-
getCROP_IMAGE_EXTRA_OPTIONS
final String getCROP_IMAGE_EXTRA_OPTIONS()
The key used to pass crop image options to CropImageActivity.
-
getCROP_IMAGE_EXTRA_BUNDLE
final String getCROP_IMAGE_EXTRA_BUNDLE()
The key used to pass crop image bundle data to CropImageActivity.
-
getCROP_IMAGE_EXTRA_RESULT
final String getCROP_IMAGE_EXTRA_RESULT()
The key used to pass crop image result data back from CropImageActivity.
-
getPICK_IMAGE_CHOOSER_REQUEST_CODE
final Integer getPICK_IMAGE_CHOOSER_REQUEST_CODE()
The request code used to start pick image activity to be used on result to identify the this specific request.
-
getPICK_IMAGE_PERMISSIONS_REQUEST_CODE
final Integer getPICK_IMAGE_PERMISSIONS_REQUEST_CODE()
The request code used to request permission to pick image from external storage.
-
getCAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE
final Integer getCAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE()
The request code used to request permission to capture image from camera.
-
getCROP_IMAGE_ACTIVITY_REQUEST_CODE
final Integer getCROP_IMAGE_ACTIVITY_REQUEST_CODE()
The request code used to start CropImageActivity to be used on result to identify the this specific request.
-
getCROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE
final Integer getCROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE()
The result code used to return error from CropImageActivity.
-
-
-
-