本文介绍了采取与Cooliris的作物图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了拍照,并在我的应用程序裁剪它。通常它完美的作品。但问题出现在与Cooliris的画廊设备。消息画廊(过程com.cooliris.media)意外停止,图像拍摄后出现。不幸的是,我没有这样的设备,并且不能对其进行测试。但我从崩溃日志堆栈跟踪。

I've implemented taking picture and cropping it in my app. Usually it works perfectly. But the problem appears on devices with Cooliris gallery. The message "Gallery(process com.cooliris.media) has stopped unexpectedly" appears after the image is taken. Unfortunately, I don't have such device, and can't test it. But I have a stacktrace from a crash log.

E/AndroidRuntime(20624): Caused by: java.lang.NullPointerException
E/AndroidRuntime(20624):    at com.cooliris.media.CropImage.loadBitmap(CropImage.java:460)
E/AndroidRuntime(20624):    at com.cooliris.media.CropImage.onCreate(CropImage.java:443)
E/AndroidRuntime(20624):    at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(20624):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(20624):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
E/AndroidRuntime(20624):    ... 11 more

在code我用它来拍摄照片:

The code I use to take a photo:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureUri = Uri.fromFile(getTempImageFile());
intent.putExtra("return-data", true);
startActivityForResult(intent, INTENT_PICK_FROM_CAMERA);

在code裁剪图像(的onActivityResult此意向):

The code to crop the image (in onActivityResult for this intent):

Intent intent = new Intent("com.android.camera.action.CROP");
intent.addCategory("android.intent.category.DEFAULT");
intent.addCategory("android.intent.category.ALTERNATIVE");
intent.addCategory("android.intent.category.SELECTED_ALTERNATIVE");
intent.setDataAndType(data.getData(), "image/jpeg");
intent.putExtra("outputX", CROPPED_IMAGE_X);
intent.putExtra("outputY", CROPPED_IMAGE_Y);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, INTENT_CROP_FROM_CAMERA);

好像data.getData()是空的,但我不知道。有谁知道什么可以是问题,如何解决它?

Seems like data.getData() is null, but I'm not sure. Does anybody know what can be the issue and how to fix it?

推荐答案

我曾与裁切功能(仅Cooliris的媒体)有问题,太:

I had a problem with the crop function (only cooliris media), too:

Cooliris的媒体异常:

Cooliris media exception:

E/AndroidRuntime(4439): java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.cooliris.media/com.cooliris.media.CropImage}: java.lang.NullPointerException
...
E/AndroidRuntime(4439): Caused by: java.lang.NullPointerException
at com.cooliris.media.CropImage.onCreate(CropImage.java:276)

我通过给予ACTION_IM​​AGE_CAPTURE意图正确的输出文件解决了这个问题。
这为我工作:

I solved the problem by giving the ACTION_IMAGE_CAPTURE intent the correct output file.This worked for me:

private static Uri tempFileUri = null;
...
String fileName = "myImg.tmp";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION, "test description");
tempFileUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
if (tempFileUri != null) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri); 
    ...
    startActivityForResult(takePictureIntent, IntentConstants.INTENT_REQUEST_CODE_TAKE_PHOTO);
}

我不使用 intent.putExtra(返回数据,真正的); 了,因为有些设备不返回数据(有的只有小的图像 - 似乎每一个设备的行为有所不同)。也许这就是为什么在Cooliris的媒体的空指针异常发生的原因(发送到Cooliris的数据为空)。这实在是烦人,只是Cooliris的崩溃...

I don't use intent.putExtra("return-data", true); anymore, because some devices don't return data (and some only small images - it seems that every device acts different). Perhaps this is the reason why the NullPointer Exception in cooliris media occurs (data sent to cooliris was null). It is really annoying that cooliris just crashes ...

在code裁剪图像(的onActivityResult此意向):

The code to crop the image (in onActivityResult for this intent):

Uri picUri = null;
if (intent.getData() != null) {
    picUri = intent.getData();
} else {
    picUri = tempFileUri;
}
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 56);
cropIntent.putExtra("outputY", 56);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, INTENT_REQUEST_CODE_CROP_PHOTO);

这篇关于采取与Cooliris的作物图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:59