在 Android 上将 Bitmap() 分享到 twitter、facebook、邮件
也许是一个简单的问题:我想将我通过网络收到的位图分享到 twitter/facebook/etc 并使用默认共享“意图”。
我找到的代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
sendIntent.putExtra(Intent.EXTRA_TEXT,
"See my captured picture - wow :)");
startActivity(Intent.createChooser(sendIntent, "share"));
需要在“IDONTKNOW”点处用位图填充。 (this.bitmap)
我发现没有办法在不将位图保存到内部 sd 的情况下处理这个问题..
问候
maybe an easy question: I want to share a bitmap I received over the net to twitter/facebook/etc with the default share "intent".
The code I found
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
sendIntent.putExtra(Intent.EXTRA_TEXT,
"See my captured picture - wow :)");
startActivity(Intent.createChooser(sendIntent, "share"));
needs to be filled at the point "IDONTKNOW" with the bitmap. (this.bitmap)
I found no way to handle this without saving the bitmap to internal sd..
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简单地说,您可以将外部存储中的位图转换为 PNG。
然后,你可以通过Uri.parse获取一个URI:
Simply, you can convert a bitmap into PNG from external storage.
Then, you can get a URI through Uri.parse:
现在可能有点晚了,但如果你不关心如何,你也可以这样做
String url = Images.Media.insertImage(context.getContentResolver(), image, "title", null);
它已被存储。Might be a little late now, but you could also do
String url = Images.Media.insertImage(context.getContentResolver(), image, "title", null);
if you don't care how it's stored.好吧,我自己得到了它,似乎没有办法在不将位图保存到磁盘的情况下获取图像 uri,因此我使用这个简单的方法:
Ok I got it on my own, it seems there is no way to get the image uri without saving the bitmap to disk, therefore I use this simple method:
发送二进制内容
使用 ACTION_SEND 操作结合设置适当的 MIME 类型并将数据的 URI 放置在额外的名为 EXTRA_STREAM 中来共享二进制数据。这通常用于共享图像,但也可用于共享任何类型的二进制内容:
source http://developer.android.com/training/sharing/send.html
Send Binary Content
Binary data is shared using the ACTION_SEND action combined with setting the appropriate MIME type and placing the URI to the data in an extra named EXTRA_STREAM. This is commonly used to share an image but can be used to share any type of binary content:
source http://developer.android.com/training/sharing/send.html