0
我正在使用Android手機上的相機拍攝圖像。拍攝圖像後,我將完整圖像作爲uri傳遞給作物意圖(com.android.camera.action.CROP)。但是,當作物意圖返回時,它會以縮略圖大小返回到可分段。我試圖將相機中的圖像保存在文件中,併發送文件的uri,但它不會在作物意圖中打開圖像。我怎樣才能從它發送回來的包裹中獲得我在作物意圖中裁切的全尺寸圖像?下面是一些我使用的代碼:從作物意圖Android全圖
public void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (resultCode != Activity.RESULT_CANCELED) {
Uri uri = null;
switch (requestCode) {
case FILE_SELECT_CODE:
if (intent.getData() != null) {
uri = intent.getData();
cropSelectedPicture(uri);
}
break;
case PICTURE_SELECT_CODE:
uri = intent.getData();
if (uri == null) {
Bundle bundle = intent.getExtras();
Bitmap photo = null;
if (bundle != null) {
photo = bundle.getParcelable("data");
}
finishChangeProfilePicture(photo);
} else {
cropSelectedPicture(uri);
}
break;
case FILE_CROP_CODE:
Bundle extras = intent.getExtras();
Bitmap thePic = extras.getParcelable("data");
uri = extras.getParcelable("uri");
finishChangeProfilePicture(thePic);
break;
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
public void showCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("crop", "true");
intent.putExtra("outputX", pictureWidth);
intent.putExtra("outputY", pictureHeight);
intent.putExtra("aspectX", pictureWidth);
intent.putExtra("aspectY", pictureHeight);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
try {
cordova.startActivityForResult(
this, Intent.createChooser(intent, "Take Picture"),
PICTURE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(context, "Please install a Camera application.",
Toast.LENGTH_SHORT).show();
}
}
public void cropSelectedPicture(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputX", pictureWidth);
intent.putExtra("outputY", pictureHeight);
intent.putExtra("aspectX", pictureWidth);
intent.putExtra("aspectY", pictureHeight);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
for (int i = 0; i < activities.size(); i++) {
String label = (String) activities.get(i).loadLabel(packageManager);
if (label.equals("Crop picture")) {
ActivityInfo activity = activities.get(i).activityInfo;
ComponentName name = new ComponentName (activity.applicationInfo.packageName,
activity.name);
intent.setComponent(name);
}
}
}
try {
cordova.startActivityForResult(this, intent, FILE_CROP_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "Please install a Cropping program", Toast.LENGTH_SHORT).show();
}
}
Android不具有''CROP' Intent':http://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html – CommonsWare
@CommonsWare我已經看到你的博客文章發佈在這個問題上。我沒有看到任何建議 - 在你的文章的圖書館之外。當畫廊安裝時,不存在的裁剪意圖不起作用。但是,當它使用Google+照片應用程序時,它會發生分裂,並且什麼也沒有發生。 – KickingLettuce
@KickingLettuce:「當畫廊安裝時不存在的裁剪意圖工作正常」 - 當設備製造商或ROM修改器未修改圖庫時,只要圖庫應用程序選擇維持此無證和不受支持的API,只要用戶選擇Gallery應用程序。所有設備上都不存在圖庫應用,取而代之的是Google+照片(如您注意的)或其他應用(根據設備製造商或ROM模特的要求)。 – CommonsWare