這是我從圖庫中選擇圖片和裁剪的意圖代碼。裁剪意圖在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