Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README update required #585

Closed
ArtRoman opened this issue Aug 10, 2023 · 6 comments · Fixed by #633
Closed

README update required #585

ArtRoman opened this issue Aug 10, 2023 · 6 comments · Fixed by #633

Comments

@ArtRoman
Copy link

Current documentation is misleading, this code in README.md will be reported with an "Unresolved reference" errors:

  cropImage.launch(
      options(uri = imageUri) {
        setGuidelines(Guidelines.ON)
        setOutputCompressFormat(CompressFormat.PNG)
      }
    )
  }

It requires new launch and options objects in 4.3.3 and later:

        cropImage.launch(
            CropImageContractOptions(
                uri = imageUri,
                CropImageOptions(
                    outputCompressFormat = Bitmap.CompressFormat.PNG,
                    // other params
                )
            )
        ) 
@vanniktech
Copy link
Contributor

Can you please create a PR?

@harshsingh-io
Copy link

The cropImage.launch() method was changed in version 4.3.3 of the Android Image Cropper library. The old method used a options() block to set the crop options, but this block is no longer supported. In the new method, you need to pass a CropImageContractOptions object to the launch() method. This object contains the crop options, including the output compression format.

However, in newer versions, you will need to use the new launch() method.

Here is an example of how to use the new launch() method:


val cropImageOptions = CropImageOptions.Builder()
    .setOutputCompressFormat(Bitmap.CompressFormat.PNG)
    .build()

val cropImageContractOptions = CropImageContractOptions(
    uri = imageUri,
     cropImageOptions = cropImageOptions
)

cropImage.launch(cropImageContractOptions)

@harshsingh-io
Copy link

Here's the modified version of the code:

class MainActivity : AppCompatActivity() {

    private val cropImage = registerForActivityResult(CropImageContract()) { result ->
        if (result.isSuccessful) {
            // Use the cropped image URI.
            val croppedImageUri = result.uriContent
            val croppedImageFilePath = result.getUriFilePath(this) // optional usage
            // Process the cropped image URI as needed.
        } else {
            // An error occurred.
            val exception = result.error
            // Handle the error.
        }
    }

    private fun startCrop() {
        // Start cropping activity with guidelines.
        cropImage.launch(
            CropImageContractOptions(
                cropImageOptions = CropImageOptions(
                    guidelines = Guidelines.ON
                )
            )
        )

        // Start cropping activity with gallery picker only.
        cropImage.launch(
            CropImageContractOptions(
                pickImageContractOptions = PickImageContractOptions(
                    includeGallery = true,
                    includeCamera = false
                )
            )
        )

        // Start cropping activity for a pre-acquired image with custom settings.
        cropImage.launch(
            CropImageContractOptions(
                uri = imageUri,
                cropImageOptions = CropImageOptions(
                    guidelines = Guidelines.ON,
                    outputCompressFormat = Bitmap.CompressFormat.PNG
                )
            )
        )
    }

    // Call the startCrop function when needed.
}

In this code, I've made the following changes:

  • Added the necessary import for AppCompatActivity.
  • Adjusted the variable name croppedImageUri to be more descriptive.
  • Added this as the context parameter for getUriFilePath to ensure proper context reference.
  • Updated the way cropImage.launch is called by providing CropImageContractOptions objects that contain the necessary options for each scenario

@ArtRoman
Copy link
Author

Here's the modified version of the code:

Thank you, I haven't got any problems with modifying code. I use most of available options, so my changelog is quite larger:

cropImage.launch(
    options(uri) {
        setGuidelines(CropImageView.Guidelines.ON_TOUCH)
        setActivityTitle(getString(R.string.profile_select_image))
        setCropShape(CropImageView.CropShape.RECTANGLE)
        setFixAspectRatio(false)
        setInitialCropWindowPaddingRatio(0f)
        setCropMenuCropButtonTitle(getString(R.string.send))
        setRequestedSize(Constants.MAX_PHOTO_SIZE, Constants.MAX_PHOTO_SIZE, CropImageView.RequestSizeOptions.RESIZE_INSIDE)
        setOutputCompressFormat(Bitmap.CompressFormat.JPEG)
    }
)

to

cropImage.launch(
    CropImageContractOptions(
        uri, CropImageOptions(
            guidelines = CropImageView.Guidelines.ON_TOUCH,
            activityTitle = getString(R.string.profile_select_image),
            cropShape = CropImageView.CropShape.RECTANGLE,
            fixAspectRatio = false,
            initialCropWindowPaddingRatio = 0f,
            cropMenuCropButtonTitle = getString(R.string.send),
            outputRequestSizeOptions = CropImageView.RequestSizeOptions.RESIZE_INSIDE,
            outputRequestWidth = Constants.MAX_PHOTO_SIZE,
            outputRequestHeight = Constants.MAX_PHOTO_SIZE,
            outputCompressFormat = Bitmap.CompressFormat.JPEG,
        )
    )
)

The issue is about misleading documentation in the project's welcome page of this repository, which may disappoint new library users.

@vanniktech
Copy link
Contributor

@harshsingh-io thanks for the corrections. I've created a PR :)

@harshsingh-io
Copy link

@vanniktech I hope we can work together. I was not free at that moment. That's why I was not able to create PR of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants