有没有一种方法来获取位图的URI而不将其保存到sdcard? [英] Is there a way to get URI of bitmap without saving it to sdcard?

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

问题描述

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

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

无需保存到SD卡的位图

a bitmap without need to saving it to sd card

我使用的代码工作正常,但是我不需要将此位图保存到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);
    }

我需要获取URI而不将位图保存到SD卡

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

}

这篇关于有没有一种方法来获取位图的URI而不将其保存到sdcard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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