Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Usage with Camera Intent? #118

Closed
xaxist opened this issue May 19, 2015 · 7 comments
Closed

Usage with Camera Intent? #118

xaxist opened this issue May 19, 2015 · 7 comments

Comments

@xaxist
Copy link

xaxist commented May 19, 2015

Hello,

This library works great for ImagePicker. Does this work with Camera capture intent? If yes, are there any examples available?

Thanks in advance.

@mike-nolan
Copy link

If this is not a feature already it would be a great one.

@xaxist
Copy link
Author

xaxist commented May 19, 2015

I have tried the following code so far. The CropImageActivity doesn't show up when image is captured.

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, REQUEST_CAPTURE_PHOTO);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CAPTURE_PHOTO && resultCode == RESULT_OK) 
    {
        Uri inputUri = data.getData();
        File cropped = new File(Environment.getExternalStorageDirectory() + "/cropped");
        if (!cropped.exists()) 
        {
            cropped.mkdir();
        }
        Uri outputUri = Uri.fromFile(new File(cropped.getAbsolutePath() + "/" + new Date().getTime() + ".png"));
        Crop.of(inputUri, outputUri).asSquare().start(this);
    }
}

@jdamcd
Copy link
Owner

jdamcd commented May 21, 2015

You can crop any local image if you have a Uri, so camera images are no different. Direct camera integration is beyond the scope of the library, but I'll try to add an example as part of #103.

@jdamcd jdamcd closed this as completed May 21, 2015
@sridharkrishna
Copy link

sridharkrishna commented May 21, 2015 via email

@xaxist
Copy link
Author

xaxist commented May 24, 2015

@jdamcd - Thanks!

@sridharananthakrishnan - If you can help me with the code, that will be great. Thanks!

@sridharkrishna
Copy link

@Anupsarode
Try like this after capturing the image using camera intent use onActivityResult() method to call the jdamcd/crop intent. Before calling the crop intent you should import the souncloud crop library into your project.

/**
* Receiving activity result method will be called after closing the camera
*/
@OverRide
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;

    switch (requestCode) {
        case REQUEST_CODE_CAPTURE_IMAGE:
            // Send image taken from camera for cropping
            cropImage();
            break;

        case Crop.REQUEST_CROP:
            // Handle Cropped Image
            handleCrop(FileUri);

    }
}

/**
* Helper Methods
*/

public Uri getOutputMediaFileUri(int type) {
    return Uri.fromFile(getOutputMediaFile(type));
}

private void beginCrop(Uri source) {
    FileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    Uri outputUri = FileUri;
    new Crop(source).output(outputUri).withAspect(0,0).start(this);
}

private void handleCrop(Uri OutputUri) {
    Intent i = new Intent(this, ProcessActivity.class);
    i.putExtra("FilePath", OutputUri.getPath());
    startActivity(i);
}

// Crop and resize the image for profile
private void cropImage() {
   beginCrop(mImageCaptureUri);
}

Thanks..! :+1

@huteri
Copy link

huteri commented Dec 17, 2015

@sridharkrishna Hi, it is not clear how you set up mImageCaptureUri, you also have to give an example about how to start the intent

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

No branches or pull requests

5 participants