https://github.com/3sidedcube/imagecropper
A version of the image cropper library that allows scrolling on the shadowed parts of the selected image.
https://github.com/3sidedcube/imagecropper
Last synced: 11 months ago
JSON representation
A version of the image cropper library that allows scrolling on the shadowed parts of the selected image.
- Host: GitHub
- URL: https://github.com/3sidedcube/imagecropper
- Owner: 3sidedcube
- License: apache-2.0
- Created: 2023-04-04T08:30:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-04T10:12:36.000Z (about 3 years ago)
- Last Synced: 2025-03-24T20:45:41.717Z (about 1 year ago)
- Language: Kotlin
- Size: 12.5 MB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/canhub)
Android Image Cropper
=====================
- **Powerful** (Zoom, Rotation, Multi-Source)
- **Customizable** (Shape, Limits, Style)
- **Optimized** (Async, Sampling, Matrix)
- **Simple** image cropping library for Android

## Add to your project
```groovy
dependencies {
implementation("com.vanniktech:android-image-cropper:4.5.0")
}
```
## Using the Library
There are 3 ways of using the library. Check out the sample app for all details.
### [1. Calling crop directly](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleCrop.kt)
```kotlin
class MainActivity {
private val cropImage = registerForActivityResult(CropImageContract()) { result ->
if (result.isSuccessful) {
// Use the returned uri.
val uriContent = result.uriContent
val uriFilePath = result.getUriFilePath(context) // optional usage
} else {
// An error occurred.
val exception = result.error
}
}
private fun startCrop() {
// Start picker to get image for cropping and then use the image in cropping activity.
cropImage.launch(
options {
setGuidelines(Guidelines.ON)
}
)
// Start picker to get image for cropping from only gallery and then use the image in cropping activity.
cropImage.launch(
options {
setImagePickerContractOptions(
PickImageContractOptions(includeGallery = true, includeCamera = false)
)
}
)
// Start cropping activity for pre-acquired image saved on the device and customize settings.
cropImage.launch(
options(uri = imageUri) {
setGuidelines(Guidelines.ON)
setOutputCompressFormat(CompressFormat.PNG)
}
)
}
}
```
### [2. Using CropView](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleUsingImageView.kt)
- Add `CropImageView` into your activity
```xml
```
- Set image to crop
```kotlin
cropImageView.setImageUriAsync(uri)
// Or prefer using uri for performance and better user experience.
cropImageView.setImageBitmap(bitmap)
```
- Get cropped image
```kotlin
// Subscribe to async event using cropImageView.setOnCropImageCompleteListener(listener)
cropImageView.getCroppedImageAsync()
// Or.
val cropped: Bitmap = cropImageView.getCroppedImage()
```
### [3. Extend to make a custom activity](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleCustomActivity.kt)
If you want to extend the `CropImageActivity` please be aware you will need to set up your `CropImageView`
- Add `CropImageActivity` into your AndroidManifest.xml
```xml
```
- Set up your `CropImageView` after call `super.onCreate(savedInstanceState)`
```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setCropImageView(binding.cropImageView)
}
```
#### Custom dialog for image source pick
When calling crop directly the library will prompt a dialog for the user choose between gallery or camera (If you keep both enable).
We use the Android default AlertDialog for this. If you wanna customised it with your app theme you need to override the method `showImageSourceDialog(..)` when extending the activity _(above)_
```kotlin
override fun showImageSourceDialog(openSource: (Source) -> Unit) {
super.showImageSourceDialog(openCamera)
}
```
## Posts
- [Android cropping image from camera or gallery](https://canato.medium.com/android-cropping-image-from-camera-or-gallery-fbe732800b08)
## Migrating from Android Image Cropper
Start by using [Version 4.3.3](https://github.com/CanHub/Android-Image-Cropper/releases/tag/4.3.3):
```groovy
dependencies {
implementation("com.vanniktech:android-image-cropper:4.3.3")
}
```
### Update all imports
```diff
-import com.theartofdev.edmodo.cropper.CropImage
-import com.theartofdev.edmodo.cropper.CropImageActivity
+import com.canhub.cropper.CropImage
+import com.canhub.cropper.CropImageActivity
```
### Update all XML references
```diff
-