【问题标题】:com.android.camera.action.CROP stuckscom.android.camera.action.CROP 卡住
【发布时间】:2014-09-27 12:37:22
【问题描述】:

我开始遵循意图:

            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            cropIntent.setDataAndType(data.getData(), "image/*");
            cropIntent.putExtra("crop", "true");
            cropIntent.putExtra("outputX", wallWidth);
            cropIntent.putExtra("outputY", wallHeight);
            cropIntent.putExtra("aspectX", wallWidth);
            cropIntent.putExtra("aspectY", wallHeight);
            cropIntent.putExtra("scale", true);
            cropIntent.putExtra("scaleUpIfNeeded", true);
            cropIntent.putExtra("return-data", true);
            cropIntent.putExtra("noFaceDetection", true);

在我的例子中,wallWidth 和 wallHeight 是 960/800,然后这个意图停留在裁剪上(这个加载圈一直在旋转)。 如果我在那里输入大约 400 或更少的输出,它会完美运行。 我怎样才能解决这个问题?因为我想有一个更高分辨率的位图作为输出。

【问题讨论】:

  • Android 没有CROP Intent: commonsware.com/blog/2013/01/23/…
  • 我知道,但有些智能手机有它
  • 是的,但“一些”不是“全部”。如果您的目标是拥有一个在大多数 Android 设备上兼容的应用程序,请不要依赖未记录、不受支持的 Intent 操作。使用库或实现您自己的图像裁剪 UI。
  • 是的,我创建了自己的裁剪 UI,但只有在上面的 Intent 不存在时才会开始。所以你不知道我的问题的答案?
  • 您的问题的答案是停止使用 Intent 操作。即使设备具有支持它的活动,该活动也可能无法正常工作。设备制造商通常会破坏对记录和支持的操作的支持(例如,ACTION_IMAGE_CAPTURE)。未记录和不受支持的操作的可靠性往往会更差。而且,既然您已经将更好的替代方案集成到您的应用中,请使用它。

标签: android android-intent crop


【解决方案1】:

大图使用Uri,小图使用Bitmap。这里需要使用Uri。

关键代码如下:

private static final String IMAGE_FILE_LOCATION = "file:///sdcard/temp.jpg";//temp file
private Uri imageUri = Uri.parse(IMAGE_FILE_LOCATION);//The Uri to store the big bitmap

startPhotoZoom(data.getData());

public void startPhotoZoom(Uri uri) {
	Intent intent = new Intent("com.android.camera.action.CROP");
	intent.setDataAndType(uri, "image/*");
	intent.putExtra("crop", "true");
	intent.putExtra("aspectX", 1);
	intent.putExtra("aspectY", 1);
	intent.putExtra("scale", true);
	intent.putExtra("outputX", 500);
	intent.putExtra("outputY", 500);
	intent.putExtra("noFaceDetection", true);
	intent.putExtra("return-data", false);
	intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
	intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
	startActivityForResult(intent, Constant.CROP_IMAGE);
}

Bitmap bitmap = decodeUriAsBitmap(imageUri);

//decode bitmap
private Bitmap decodeUriAsBitmap(Uri uri){
	Bitmap bitmap = null;
	try {
		bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
	} catch (FileNotFoundException e) {
		e.printStackTrace();
		return null;
	}
	return bitmap;
}

【讨论】:

    猜你喜欢
    • 2013-02-26
    • 2017-12-29
    • 2011-08-04
    • 2011-11-17
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多