How to get Bitmap from an Uri?

前端 未结 16 1380
时光说笑
时光说笑 2020-11-22 10:41

How to get a Bitmap object from an Uri (if I succeed to store it in /data/data/MYFOLDER/myimage.png or file///data/data/MYFOLDER/myimage.png) to u

16条回答
  •  甜味超标
    2020-11-22 11:04

    Full method to get image uri from mobile gallery.

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
      if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
                    Uri filePath = data.getData();
    
         try { //Getting the Bitmap from Gallery
               Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
               rbitmap = getResizedBitmap(bitmap, 250);//Setting the Bitmap to ImageView
               serImage = getStringImage(rbitmap);
               imageViewUserImage.setImageBitmap(rbitmap);
          } catch (IOException e) {
               e.printStackTrace();
          }
    
    
       }
    }
    

提交回复
热议问题