Android图片裁剪意图无法正常工作

时间:2014-05-22 15:04:25

标签: android android-intent

我尝试裁剪图像,有时它的工作完美但是大多数时候我在onActivityResult上得到了null值并在日志中显示以下错误以及如何解决这个问题,请帮助我。

这是调用裁剪意图的代码

Intent intent = new Intent("com.android.camera.action.CROP");
Uri myUri = Uri.fromFile(mFileTemp);  // mFileTemp this is the image file name 
intent.setDataAndType(myUri, "image/*");
intent.putExtra("outputX", 100);
intent.putExtra("outputY", 100);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("crop", "true");
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP_FROM_CAMERA)

onActivityResult代码:

case CROP_FROM_CAMERA:
           try {
               if (data != null) {
                   Bundle extras = data.getExtras();
                   if (extras != null) {
                      Bitmap photo = extras.getParcelable("data");
                      imageView.setImageBitmap(photo);
                   }
               }
           } catch (Exception e) {

           }
           break;
       }

错误日志:

05-22 18:06:58.687: E/AndroidRuntime(12610): FATAL EXCEPTION: main
05-22 18:06:58.687: E/AndroidRuntime(12610): java.lang.RuntimeException: Unable to resume activity {com.example/com.example.userprofile.UserProfile}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.example/com.example.userprofile.UserProfile}: java.lang.NullPointerException
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2639)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.access$700(ActivityThread.java:143)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.os.Looper.loop(Looper.java:137)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.main(ActivityThread.java:4950)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at java.lang.reflect.Method.invokeNative(Native Method)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at java.lang.reflect.Method.invoke(Method.java:511)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at dalvik.system.NativeStart.main(Native Method)
05-22 18:06:58.687: E/AndroidRuntime(12610): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.example/com.example.userprofile.UserProfile}: java.lang.NullPointerException
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2626)
05-22 18:06:58.687: E/AndroidRuntime(12610):    ... 12 more
05-22 18:06:58.687: E/AndroidRuntime(12610): Caused by: java.lang.NullPointerException
05-22 18:06:58.687: E/AndroidRuntime(12610):    at com.example.userprofile.UserProfile.onActivityResult(UserProfile.java:285)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.Activity.dispatchActivityResult(Activity.java:5361)
05-22 18:06:58.687: E/AndroidRuntime(12610):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
05-22 18:06:58.687: E/AndroidRuntime(12610):    ... 13 more  

0 个答案:

没有答案