How to get a Uri object from Bitmap

后端 未结 7 1637
醉话见心
醉话见心 2020-12-09 15:55

On a certain tap event, I ask the user to add an image. So I provide two options:

  1. To add from gallery.
  2. To click a new image from camera.
7条回答
  •  误落风尘
    2020-12-09 16:44

    Note : if you are using android 6.0 or greater version path will give null value. so you have to add permission

    public void onClicked(View view){
            Bitmap bitmap=getBitmapFromView(scrollView,scrollView.getChildAt(0).getHeight(),scrollView.getChildAt(0).getWidth());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG,90,baos);
            String path = MediaStore.Images.Media.insertImage(getContentResolver(),bitmap,"title",null);
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/jpeg");
            intent.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));
            startActivity(Intent.createChooser(intent,"Share Screenshot Using"));
        }
    

提交回复
热议问题