Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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 共享未保存的图像_Android_Image_Data Sharing - Fatal编程技术网

Android 共享未保存的图像

Android 共享未保存的图像,android,image,data-sharing,Android,Image,Data Sharing,我想分享一个新创建的图像,因此未保存。它存储在位图对象中。在本文中,您需要具有图像的URI: shareIntent.putExtra(Intent.EXTRA_流,uriToImage) 但是,是否可以在不保存图像的情况下共享图像?您可以使用以下代码: ByteArrayOutputStream bos = new ByteArrayOutputStream(); yourBitmapObj.compress(Bitmap.CompressFormat.JPEG, 75, bo

我想分享一个新创建的图像,因此未保存。它存储在
位图
对象中。在本文中,您需要具有图像的URI:
shareIntent.putExtra(Intent.EXTRA_流,uriToImage)

但是,是否可以在不保存图像的情况下共享图像?

您可以使用以下代码:

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    yourBitmapObj.compress(Bitmap.CompressFormat.JPEG, 75, bos);
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("image/jpeg");
    intent.putExtra(Intent.EXTRA_STREAM, bos.toByteArray());
    startActivity(Intent.createChooser(intent, "Send to"));
但是,如果你想通过Instagram等流行应用程序进行共享,我知道他们试图解析
Uri
,但没有获得
ByteArray
,你会收到应用程序的异常