0

我想在从相机拍摄后裁剪图像。我正在使用此代码。

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

但它给出了错误:找不到活动。我的安卓版本是4.2.2。

我也试过。

Intent intent = new Intent(Intent.ACTION_PICK);

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

4

2 回答 2

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>

主要活动

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);

    }
    }       
    }        
    } 

结果快照

在此处输入图像描述

于 2013-05-05T09:45:35.987 回答
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/

于 2013-05-05T09:00:30.190 回答