Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从gallery中拾取图像并显示后,AlertDialog中的ImageView为空 (这是一个对话框,它显示了我试图在我的自定义对话框中从图库中显示所选图像到 IVIEVIEW 的对话框,但是 IVIEVIEW 出现空白。虽然它不是NULL。下面是下面的代码片段: public void loadImagefromGallery(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, SELECT_PHOTO); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try { if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); final Dialog dialog = new Dialog(SelectImagesActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.upload_image); ImageView imageView = (ImageView) dialog.findViewById(R.id.imageView1); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); EditText editText = (EditText)dialog.findViewById(R.id.keyWords); Button button = (Button)dialog.findViewById(R.id.done); dialog.setCancelable(false); dialog.getWindow().setLayout(550, 900); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); } else { Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) .show(); } }_Android_Android Intent_Imageview_Android Dialog - Fatal编程技术网

Android 从gallery中拾取图像并显示后,AlertDialog中的ImageView为空 (这是一个对话框,它显示了我试图在我的自定义对话框中从图库中显示所选图像到 IVIEVIEW 的对话框,但是 IVIEVIEW 出现空白。虽然它不是NULL。下面是下面的代码片段: public void loadImagefromGallery(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, SELECT_PHOTO); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try { if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); final Dialog dialog = new Dialog(SelectImagesActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.upload_image); ImageView imageView = (ImageView) dialog.findViewById(R.id.imageView1); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); EditText editText = (EditText)dialog.findViewById(R.id.keyWords); Button button = (Button)dialog.findViewById(R.id.done); dialog.setCancelable(false); dialog.getWindow().setLayout(550, 900); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); } else { Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) .show(); } }

Android 从gallery中拾取图像并显示后,AlertDialog中的ImageView为空 (这是一个对话框,它显示了我试图在我的自定义对话框中从图库中显示所选图像到 IVIEVIEW 的对话框,但是 IVIEVIEW 出现空白。虽然它不是NULL。下面是下面的代码片段: public void loadImagefromGallery(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, SELECT_PHOTO); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try { if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); final Dialog dialog = new Dialog(SelectImagesActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.upload_image); ImageView imageView = (ImageView) dialog.findViewById(R.id.imageView1); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); EditText editText = (EditText)dialog.findViewById(R.id.keyWords); Button button = (Button)dialog.findViewById(R.id.done); dialog.setCancelable(false); dialog.getWindow().setLayout(550, 900); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); } else { Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) .show(); } },android,android-intent,imageview,android-dialog,Android,Android Intent,Imageview,Android Dialog,任何帮助都将不胜感激。谢谢。更改 dialog.show(); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 到 改变 dialog.show(); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 到 改为: imageView.setImageURI(Uri.parse(picturePath)); 改为: imag

任何帮助都将不胜感激。谢谢。

更改

 dialog.show();
 imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

改变

 dialog.show();
 imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

改为:

imageView.setImageURI(Uri.parse(picturePath));
改为:

imageView.setImageURI(Uri.parse(picturePath));

共享屏幕截图。Is
String picturePath=cursor.getString(columnIndex);
返回图像的正确绝对路径。共享屏幕截图。Is
String picturePath=cursor.getString(columnIndex);
返回图像的正确绝对路径。