我想在從相機捕捉後裁剪圖像。 我正在使用此代碼。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);
但它會打開畫廊而不是捕獲的圖像。
我想在從相機捕捉後裁剪圖像。 我正在使用此代碼。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);
但它會打開畫廊而不是捕獲的圖像。
使用下面的代碼這將幫助你。
//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/
這個鱈魚不適用於android 4.2.2。 – 2013-05-05 09:01:38
下面的工作對我的三星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卡
它給出空指針異常。 – 2013-05-05 12:51:19
@HarisAli發佈相關代碼和logcat詳細信息 – Raghunandan 2013-05-05 14:02:52
我使用了確切的代碼。 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
看看這個[問題](http://stackoverflow.com/questions/10632137/android-calling-crop-activity-after-taking-photo) – mprabhat 2013-05-05 08:48:12
看看這個.http:// www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html – itsrajesh4uguys 2013-05-05 08:59:21
我檢查了這個,但沒有工作。 – 2013-05-05 09:02:00