Android Crop Image Error

You must Login before you can answer or comment on any questions.

Hi, i have implemented a crop image for Android 4.0.3 and Titanium sdk 2.1.0. I open the gallery of android , crop and save. My problem is that I cannot obtain the cropped image. In the Emulator works all fine and the path is returned in e1.intent.action. This is my code

Titanium.Media.openPhotoGallery({
        success : function(event) {                              
            var image = event.media;            
            var intent = Ti.Android.createIntent({
                action: "com.android.camera.action.CROP",
                data: image.nativePath,
                type: 'image/*'
            });
            intent.putExtra("outputX", 200);
            intent.putExtra("outputY", 200);
            intent.putExtra("aspectX", 1);
            intent.putExtra("aspectY", 1);
            intent.putExtra("scale", true);                             
            var activity = Ti.Android.currentActivity;
            activity.startActivityForResult(intent, function(e1) {                  
                var pathImage: e1.intent.action;                    
            });
        },
        error:function(error)
        {            
        },
        cancel : function() 
        {
        }
    });
What is wrong?

Thank you

— asked 12 months ago by Sergio Falcone
1 Comment
  • Am not sure try with this changes var pathImage: e1.intent.action;// make change here

    var pathImage = e1.intent.action;

    — commented 6 weeks ago by Nagaraja Devadiga

6 Answers

I tried your code, e1.intent.data is NULL and e1.intent.getStringExtra("data") IS NULL as well. Below is my code, i would appreciate it if you could direct me

var intent = Ti.Android.createIntent({
                    action: "com.android.camera.action.CROP",                   
                    data: houseimage.nativePath,                    
                    type: 'image/*'     
                });
                //intent.putExtra("crop", "true");
                intent.putExtra("outputX", 200);
                intent.putExtra("outputY", 200);
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
                intent.putExtra("scale", true);
                intent.putExtra(Ti.Android.EXTRA_STREAM, Ti.Filesystem.applicationDataDirectory);
 
                var activity = Ti.Android.currentActivity;              
                activity.startActivityForResult(intent, function(param){
                    var toast = Ti.UI.createNotification({
                            message: JSON.stringify(param.intent.getStringExtra("data"))
                        });
                        toast.show();
                });

— answered 12 months ago by Hiren Sharma
answer permalink
5 Comments
  • What version of android are you using? For me worked only for android 4.0 or later. I have tested on Asus TF101.

    — commented 12 months ago by Sergio Falcone

  • I am testing on 4.0.3, on my HTC ONE X

    — commented 12 months ago by Hiren Sharma

  • But the cropped image is saved? If not you must check if you have write permissions in your app, to do what you have to go in the build/Android of your project and check the file AndroidManifest.xml if there is the following line: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    — commented 12 months ago by Sergio Falcone

  • Show 2 more comments

Yes, I have the solution. In the physical device the path of the cropped image is returned into:

e1.intent.data
Thats works for me.

Hi, I'm having the same problem over here. It seems that the callback for activity.startActivityForResult is not being called at all. I can't retrieve the cropped picture...

I created a simple test project with my code here.

Note that navBarHidden:true and window.open({modal:true}); prevent to invoke activityResult.

— answered 12 months ago by Sergio Falcone
answer permalink
3 Comments
  • I tried your code and on my HTC one x, its giving me Alert Error Message... In other words it's not working on my Device

    — commented 11 months ago by Hiren Sharma

  • Hi Sergio, I tried your code on a Motorola Defy running android 2.3.4 and a Samsung Galaxy Tab 2 I'm getting the error message too, but that's a fixable error. As I can see, in your code, the callback function is being called. My code is exactly the same as yours, but in my app, the callback functions is not called. Almost all my app's windows are set navBarHidden:true, but I managed to open a new window without that property set and the problem still.

    Maybe neither the window that opens the window that calls the can have the navBarHidden property set true. I don't know, I've tried everything. I guess there is something else causing this bug.

    — commented 11 months ago by Andre Perazzi

  • I tried so many ways to make an image cropper for Android, either with imageViews, views, etc, without success. I guess I'll leave my Android's version of the app without that feature until this problem get fixed

    — commented 11 months ago by Andre Perazzi

Was anyone able to get this to work?

I can not seem to get a path to the newly saved cropped image. It gets stored in the gallery and everything.

Thanks.

Your Answer

Think you can help? Login to answer this question!