作物保存的图像使用com.android.camera.action.CROP在Android [英] Crop saved Image using com.android.camera.action.CROP on android
本文介绍了作物保存的图像使用com.android.camera.action.CROP在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读这个很多问题,但我还是失败了使用这种code ...也许任何人都可以corect我的code ......我要裁剪从文件的图像,我知道使用位置com.android.camera.action.CROP像这样...
I have reads many question about this, but I still failed using this code... maybe anyone can corect my code... I want to crop an image from file that i know the location using com.android.camera.action.CROP like this...
mImageCaptureUri = Uri.fromFile(f);
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
intent.setData(mImageCaptureUri);
intent.putExtra("crop", true);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
Bundle extras = intent.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("intent");
tampilan.setImageBitmap(photo);
}
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) f.delete();
但是,当我运行code,没有什么hapend ... T.T 谁能帮助我?
But when i run the code, nothing hapend... T.T can anyone help me??
推荐答案
我已经修改我的code和它的作品全成,这是我的code ..
I had modify my code and its works successfull, this is my code..
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("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(selectImageUri);
intent.putExtra("outputX", 300);
intent.putExtra("outputY", 300);
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 {
}
}
和这样的activityResult
and the activityResult like this
if (resultCode == RESULT_OK){
switch (requestCode){
case SELECT_PICTURE :
selectImageUri = data.getData();
doCrop();
break;
case CROP_RESULT :
Bundle extras = data.getExtras();
if (extras != null) {
bmp = extras.getParcelable("data");
temporary.setBitmap(bmp);
}
File f = new File(selectImageUri.getPath());
if (f.exists()) f.delete();
Intent inten3 = new Intent(this, tabActivity.class);
startActivity(inten3);
break;
case CAMERA_IMAGE :
doCrop();
break;
}
}
也许它很有用:D
maybe its useful :D
这篇关于作物保存的图像使用com.android.camera.action.CROP在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文