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

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

问题描述

在某个点击事件中,我要求用户添加图像.所以我提供了两个选项:

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

  1. 从图库添加.
  2. 点击来自相机的新图像.

我的目标是保留与这些图像相关的uri"列表.

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

如果用户选择图库,那么我会得到图像 uri(这很简单).但是如果他选择相机,那么在拍完一张照片后,我得到了那张照片的Bitmap对象.

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.

现在如何将该 Bitmap 对象转换为 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 = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
  return Uri.parse(path);
} 

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

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