Skip to content

Commit a25c2c8

Browse files
authored
Documentation: Update README. (#633)
1 parent 6aebb15 commit a25c2c8

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,53 @@ There are 3 ways of using the library. Check out the sample app for all details.
2525
### [1. Calling crop directly](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleCrop.kt)
2626

2727
```kotlin
28-
class MainActivity {
28+
class MainActivity : AppCompatActivity() {
2929
private val cropImage = registerForActivityResult(CropImageContract()) { result ->
3030
if (result.isSuccessful) {
31-
// Use the returned uri.
32-
val uriContent = result.uriContent
33-
val uriFilePath = result.getUriFilePath(context) // optional usage
31+
// Use the cropped image URI.
32+
val croppedImageUri = result.uriContent
33+
val croppedImageFilePath = result.getUriFilePath(this) // optional usage
34+
// Process the cropped image URI as needed.
3435
} else {
3536
// An error occurred.
3637
val exception = result.error
38+
// Handle the error.
3739
}
3840
}
3941

4042
private fun startCrop() {
41-
// Start picker to get image for cropping and then use the image in cropping activity.
43+
// Start cropping activity with guidelines.
4244
cropImage.launch(
43-
options {
44-
setGuidelines(Guidelines.ON)
45-
}
45+
CropImageContractOptions(
46+
cropImageOptions = CropImageOptions(
47+
guidelines = Guidelines.ON
48+
)
49+
)
4650
)
4751

48-
// Start picker to get image for cropping from only gallery and then use the image in cropping activity.
52+
// Start cropping activity with gallery picker only.
4953
cropImage.launch(
50-
options {
51-
setImagePickerContractOptions(
52-
PickImageContractOptions(includeGallery = true, includeCamera = false)
54+
CropImageContractOptions(
55+
pickImageContractOptions = PickImageContractOptions(
56+
includeGallery = true,
57+
includeCamera = false
5358
)
54-
}
59+
)
5560
)
5661

57-
// Start cropping activity for pre-acquired image saved on the device and customize settings.
62+
// Start cropping activity for a pre-acquired image with custom settings.
5863
cropImage.launch(
59-
options(uri = imageUri) {
60-
setGuidelines(Guidelines.ON)
61-
setOutputCompressFormat(CompressFormat.PNG)
62-
}
64+
CropImageContractOptions(
65+
uri = imageUri,
66+
cropImageOptions = CropImageOptions(
67+
guidelines = Guidelines.ON,
68+
outputCompressFormat = Bitmap.CompressFormat.PNG
69+
)
70+
)
6371
)
6472
}
73+
74+
// Call the startCrop function when needed.
6575
}
6676
```
6777

0 commit comments

Comments
 (0)