有没有办法在不将其保存到 SD 卡的情况下获取位图的 URI? [英] Is there a way to get URI of bitmap without saving it to sdcard?

查看:25
本文介绍了有没有办法在不将其保存到 SD 卡的情况下获取位图的 URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,允许用户使用 android 意图共享图像,但如何获取

I am making an app that allows the user to share an image using android intent but how to get that URI of

位图无需保存到sd卡

我使用的这段代码运行良好,但我不需要将此位图保存到 sd 卡

I have used this code that works fine, but I don't need to save this bitmap to sd card

private 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);
    }

我需要在不将该位图保存到 SD 卡的情况下获取该 URI

I need to get that URI without saving that bitmap to sd card

推荐答案

试试这个:

protected void ShareImage(Intent intent) {
    try {
        URL url = new URL(mImageUrl);
        Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        intent.putExtra(Intent.EXTRA_STREAM, getImageUri(mActivity, image));
    } catch (Exception e) {
        e.printStackTrace();
    }
    startActivityForResult(Intent.createChooser(intent, 1001));
}

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    //check for result is OK and then check for your requestCode(1001) and then delete the file

}

这篇关于有没有办法在不将其保存到 SD 卡的情况下获取位图的 URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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