如何将位图转换为 Uri? [英] How can I transform a Bitmap into a Uri?

查看:24
本文介绍了如何将位图转换为 Uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Android 中的 SHARE INTENT 与 Facebook、Twitter 等分享图片.

I'm trying to share images with Facebook, twitter, etc using SHARE INTENT from Android.

我找到了将图像发送到共享意图的代码,但此代码需要位图的 URI:fullSizeImageUri

I found code to send a image to the share intent, but this code needs the URI of the bitmap: fullSizeImageUri

这是完整的代码:

private void startShareMediaActivity(Bitmap image) {
    boolean isVideo=false;
    String mimeType="bmp";
    Uri fullSizeImageUri=null;
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_STREAM, fullSizeImageUri);
    try {
        startActivity(Intent.createChooser(intent, (isVideo ? "video" : "image")));
    } catch (android.content.ActivityNotFoundException ex) { }
}

如何将位图转换为 Uri?

How to transform a Bitmap into a Uri?

推荐答案

String FILENAME = "image.png";
String PATH = "/mnt/sdcard/"+ FILENAME;
File f = new File(PATH);
Uri yourUri = Uri.fromFile(f);

这篇关于如何将位图转换为 Uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆