2013-05-05 95 views
0

我想在从相机捕捉后裁剪图像。 我正在使用此代码。Android 4.2.2中的Android裁剪图像

Intent cropIntent = new Intent("com.android.camera.action.CROP"); 

但它给出错误: 未找到活动。 我的android版本是4.2.2。

我也试过了。

Intent intent = new Intent(Intent.ACTION_PICK); 

但它会打开画廊而不是捕获的图像。

+0

看看这个[问题](http://stackoverflow.com/questions/10632137/android-calling-crop-activity-after-taking-photo) – mprabhat 2013-05-05 08:48:12

+0

看看这个.http:// www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html – itsrajesh4uguys 2013-05-05 08:59:21

+0

我检查了这个,但没有工作。 – 2013-05-05 09:02:00

回答

0

使用下面的代码这将帮助你。

//call the standard crop action intent (the user device may not support it) 
Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
    //indicate image type and Uri 
cropIntent.setDataAndType(picUri, "image/*"); 
    //set crop properties 
cropIntent.putExtra("crop", "true"); 
    //indicate aspect of desired crop 
cropIntent.putExtra("aspectX", 1); 
cropIntent.putExtra("aspectY", 1); 
    //indicate output X and Y 
cropIntent.putExtra("outputX", 256); 
cropIntent.putExtra("outputY", 256); 
    //retrieve data on return 
cropIntent.putExtra("return-data", true); 
    //start the activity - we handle returning in onActivityResult 
startActivityForResult(cropIntent, PIC_CROP); 

更多细节 http://mobile.tutsplus.com/tutorials/android/capture-and-crop-an-image-with-the-device-camera/

+0

这个鳕鱼不适用于android 4.2.2。 – 2013-05-05 09:01:38

0

下面的工作对我的三星Galaxy S3。检查拍摄

使用此捕获图像的相机

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context=".MainActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

MainActivity

public class MainActivity extends Activity { 

private static final int PICK_FROM_CAMERA = 1; 
ImageView iv; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    iv = (ImageView) findViewById(R.id.imageView1); 
    Button buttonCamera = (Button) findViewById(R.id.button1); 
    buttonCamera.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
     // call android default camera 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

     intent.putExtra(MediaStore.EXTRA_OUTPUT, 
     MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); 
     // ******** 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) { 

     } 
     } 
     }); 


} 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if (requestCode == PICK_FROM_CAMERA) { 
    Bundle extras = data.getExtras(); 
    if (extras != null) { 
    Bitmap photo = extras.getParcelable("data"); 
    iv.setImageBitmap(photo); 

    } 
    }  
    }   
    } 

得到的抽点

01卡

+0

它给出空指针异常。 – 2013-05-05 12:51:19

+0

@HarisAli发布相关代码和logcat详细信息 – Raghunandan 2013-05-05 14:02:52

+0

我使用了确切的代码。 java.lang.RuntimeException:将结果ResultInfo {who = null,request = 1,result = 0,data = null}传递给activity {com.example.crop/com.example.crop.MainActivity}:java.lang .NullPointerException – 2013-05-05 14:35:19