如何从位图一个Uri对象 [英] How to get a Uri object from Bitmap

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

问题描述

在一定的敲击事件,我要求用户添加一个图像。所以,我提供了两个选项:

On a certain tap event, I ask the user to add an image. So I provide two options:

  1. 要由画廊添加。
  2. 要请从相机的新形象。

我的目标就是保持与这些图像URI的List。

My aim is to keep a list of "uri"s related to those images.

如果用户选择库,然后我得到的图像URI(这是很简单的)。 但是,如果他选择的相机,然后拍摄照片后,我得到了画面的位图对象。

If the user chooses gallery, then I get the image uri (which is quite simple). But if he chooses camera, then after taking a picture, I am getting the Bitmap object of that picture.

现在我怎么转换成位图对象的URI,或者换句话说,我怎么能得到那个位图对象的相对Uri对象?

Now how do I convert that Bitmap object to uri, or in other words, how can I get the relative Uri object of that bitmap object?

感谢。

推荐答案

我有同样的问题,在我的项目,所以我按照简单的方法(的点击此处)从位图获得URI。

I have same problem in my project, so i follow the simple method (click here) to get Uri from bitmap.

public 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对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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