gpt4 book ai didi

android - 如何从位图中获取 Uri 对象

转载 作者:IT老高 更新时间:2023-10-28 22:16:48 25 4
gpt4 key购买 nike

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

  1. 从图库中添加。
  2. 点击相机中的新图片。

我的目标是保留与这些图像相关的“uri”列表。

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

现在我如何将该 Bitmap 对象转换为 uri,或者换句话说,如何获取该位图对象的相对 Uri 对象?

谢谢。

最佳答案

我在我的项目中遇到了同样的问题,所以我按照简单的方法(click here)从位图中获取 Uri。

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

关于android - 如何从位图中获取 Uri 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12555420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com