我正在使用代码从图库中获取位图并将其用于我的目的。这是代码:
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
if (resultCode == RESULT_OK) {
Uri targetUri = data.getData();
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeFile(getRealPathFromURI(targetUri));
//bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
addMarker(bitmap);
}
}
public String getRealPathFromURI(Uri contentUri) {
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
由于某种原因,应用程序在执行此操作时崩溃。问题不在于 addMarker 方法,因为它与测试的其他位图一起工作正常。只有来自画廊的位图它不会工作和粉碎。
这就是我得到的错误:
09-29 21:28:35.960: E/AndroidRuntime(4746):
java.lang.RuntimeException: Failure delivering result ResultInfo
{who=null, request=1, result=-1, data=Intent
{ dat=content://media/external/images/media/3 }} to activity
{com.sit.augmented_reality/com.sit.augmented_reality.activity.Demo}:
java.lang.NullPointerException