Android - Image Picker, Wrong Image

后端 未结 5 1112
情书的邮戳
情书的邮戳 2021-02-19 05:12

I am starting a request for an image pick:

Intent intent = new Intent();
intent.setType( \"image/*\" );
intent.setAction( Intent.ACTION_GET_CONTENT );
startActiv         


        
5条回答
  •  伪装坚强ぢ
    2021-02-19 05:37

    This is the code to open gallery. However this the same what you have done. Also see the onActivityResult code which I used to retrive the selected image.

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),  
                           PHOTO_GALLERY);
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case PHOTO_GALLERY:
            if (resultCode == RESULT_OK) {
                Uri selectedImageUri = Uri.parse(data.getDataString());
                try {
                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(  
                                       getApplicationContext().getContentResolver(),   
                                       selectedImageUri);
    
                    this.postImagePreview.setImageBitmap( bitmap);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            }
        }
    }
    

提交回复
热议问题