这是我从图库中选择图片和裁剪的意图代码。裁剪意图在Android中无法正常工作
int PICK_IMAGE_REQUEST = 100;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 150);
intent.putExtra("aspectY", 150);
intent.putExtra("outputX", 150);
intent.putExtra("outputY", 150);
intent.putExtra("return-data", true);
getActivity().startActivityForResult(Intent.createChooser(intent,
"Complete using with."), PICK_IMAGE_REQUEST);
这里是我的onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
int PICK_IMAGE_REQUEST = 100;
Bundle extras = null;
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK) {
extras = data.getExtras();
}
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
ImageView profilePhoto = (ImageView) findViewById(R.id.profileImageView);
profilePhoto.setImageBitmap(photo);
}
这些码以上的作物&集图像成功。但是,有时它不能正常工作。我的意思是当我使用第三方图库应用程序而不是使用设备的默认图库应用程序。它不设置图像。当使用其他图库应用程序时,这可能无法正确获取文件路径。那么,如何实现选择&裁剪并将图像设置为imageview?我研究了互联网,但迄今为止没有解决这个问题。
我也使用了ACTION_GET_CONTENT,但结果是一样的。除了你能给我代码的例子吗?感谢您的回答 – Musti
@Musti:“我也使用了ACTION_GET_CONTENT,但结果与我写的一样” - 您在那里的各种附加内容不是ACTION_PICK文档的一部分**或任何其他官方文档* *“(强调增加)。对于任何操作字符串,这些附加内容都没有记录。 “除了你能给我代码的例子吗?” - 选择一个具有代码示例的库。 – CommonsWare