从相机拍摄照片并裁剪

时间:2013-05-18 00:02:22

标签: android android-camera android-camera-intent

我试着用相机拍照并在那之后裁剪。为此,请使用以下代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == PICK_FROM_CAMERA && resultCode == Activity.RESULT_OK)
    {
        Bundle extras = data.getExtras();
        if (extras != null) 
        {
            Bitmap photo = extras.getParcelable("data");
            //iv.setImageBitmap(photo);
        }
    }
}

public void ImageClicked(View v)
{   
    // call android default camera
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, PICK_FROM_CAMERA);

    // ******** code for crop image
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 0);
    intent.putExtra("aspectY", 0);
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 150);

    try 
    {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, PICK_FROM_CAMERA);
    } 
    catch (ActivityNotFoundException e) 
    {
        // Do nothing for now
    }
}

我可以完美地拍摄照片,但之后我的应用程序崩溃了这个错误:“很遗憾Galerie已经停止了”。我的清单看起来像这样:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

这是我的错误中的CatLog:

05-18 01:55:00.580: E/caladbolg(180): 3118424938 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.620: E/caladbolg(180): 3118460460 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.650: E/caladbolg(180): 3118491924 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.680: E/caladbolg(180): 3118525585 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.720: E/caladbolg(180): 3118559429 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.750: E/caladbolg(180): 3118592937 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.783: E/caladbolg(180): 3118626598 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.820: E/caladbolg(180): 3118660320 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.850: E/caladbolg(180): 3118694469 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:00.890: E/caladbolg(180): 3118727642 cald_hal_qct.c                   (15716) 25052 E [HCF] Not found unlocked buffer.
05-18 01:55:10.950: E/AudioHardware7x30(180): updateDeviceInfo: E rx_device 2 and tx_device 3
05-18 01:55:10.950: E/AudioHardware7x30(180): updateDeviceInfo: X cur_rx 2 cur_tx 3
05-18 01:55:11.630: E/AndroidRuntime(24928): FATAL EXCEPTION: main
05-18 01:55:11.630: E/AndroidRuntime(24928): java.lang.IllegalStateException: Could not execute method of the activity
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.view.View$1.onClick(View.java:3591)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.view.View.performClick(View.java:4084)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.view.View$PerformClick.run(View.java:16966)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.os.Handler.handleCallback(Handler.java:615)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.os.Looper.loop(Looper.java:137)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.app.ActivityThread.main(ActivityThread.java:4931)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at java.lang.reflect.Method.invokeNative(Native Method)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at java.lang.reflect.Method.invoke(Method.java:511)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at dalvik.system.NativeStart.main(Native Method)
05-18 01:55:11.630: E/AndroidRuntime(24928): Caused by: java.lang.reflect.InvocationTargetException
05-18 01:55:11.630: E/AndroidRuntime(24928):    at java.lang.reflect.Method.invokeNative(Native Method)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at java.lang.reflect.Method.invoke(Method.java:511)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.view.View$1.onClick(View.java:3586)
05-18 01:55:11.630: E/AndroidRuntime(24928):    ... 11 more
05-18 01:55:11.630: E/AndroidRuntime(24928): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=file:///data/data/com.android.gallery3d/files/crop-temp (has extras) }
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.app.Activity.startActivityForResult(Activity.java:3351)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at android.app.Activity.startActivityForResult(Activity.java:3312)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at com.android.camera.Camera.doAttach(Camera.java:1442)
05-18 01:55:11.630: E/AndroidRuntime(24928):    at com.android.camera.Camera.onReviewDoneClicked(Camera.java:1362)
05-18 01:55:11.630: E/AndroidRuntime(24928):    ... 14 more
05-18 01:55:29.900: E/RadioFeedRequest(24881): Invalid value for content filter: 1

我的问题在哪里?我需要改变什么?

0 个答案:

没有答案