我正在尝试在我的 Android 平板电脑中进行裁剪,但它不起作用。
我正在使用 Nexus 10。
嗯......这是我的裁剪代码:
private void doCrop(){
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(mImageCaptureUri, "image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
if (size == 0) {
Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
return;
} else {
intent.setData(mImageCaptureUri);
intent.putExtra("outputX", 648);
intent.putExtra("outputY", 486);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROP_RESULT);
} else {
}
}
}
这是我询问“相机”或“画廊”的对话框:
private void startDialog() {
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("Selecione uma foto!");
myAlertDialog.setMessage("Choose a source");
myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
pictureActionIntent.setType("image/*");
pictureActionIntent.putExtra("return-data", true);
startActivityForResult(pictureActionIntent, GALLERY_PICTURE);
}
});
myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp/android.jpg";
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, storagePath);
startActivityForResult(pictureActionIntent, CAMERA_PICTURE);
}
});
myAlertDialog.show();
}
这是我的 onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bmp;
if (resultCode == RESULT_OK){
switch (requestCode){
case GALLERY_PICTURE :
mImageCaptureUri = data.getData();
doCrop();
break;
case CROP_RESULT :
Bundle extras = data.getExtras();
if (extras != null) {
bmp = extras.getParcelable("data");
bmp = Bitmap.createScaledBitmap(bmp, 648, 486, true);
Drawable d = new BitmapDrawable(getResources(),bmp);
btnTitular.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
}
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) f.delete();
Intent inten3 = new Intent(this, CadTitularActivity.class);
startActivity(inten3);
break;
case CAMERA_PICTURE :
doCrop();
break;
}
}
}
这是正在发生的事情:
当我从图库中抓取图像时,会显示裁剪,但是当我单击“确定”以裁剪图像时,它什么也不做。
当我从相机中抓取一张照片时,它什么也没做。它只显示“加载图片”,没有任何反应。
有任何想法吗?
请记住:我使用的是 Nexus 10。我已经听说这种裁剪内容不适用于所有设备。
欢迎任何帮助!
谢谢!