How to share image of imageview?

后端 未结 6 1884
余生分开走
余生分开走 2021-01-14 16:47

I have ImageView and I want to share its image.

Following is my code,

btshare.setOnClickListener(new OnClickListener() {

        @Override
                 


        
6条回答
  •  失恋的感觉
    2021-01-14 17:29

    • get bitmap from imageview
    imageview.buildDrawingCache();
    Bitmap image = mainimg.getDrawingCache();
    
    • convert url
    public Uri getImageUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
      return Uri.parse(path);
    }
    
    • then share button
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    share.putExtra(Intent.EXTRA_STREAM, getImageUri(this,getImageUri));
    startActivity(Intent.createChooser(share,"Share via"));
    

提交回复
热议问题