【问题标题】:Create bitmap after selecting image from Photo application in android从 Android 中的照片应用程序中选择图像后创建位图
【发布时间】:2014-12-23 23:35:24
【问题描述】:

我们有以下 FilePath fileUri: content://com.google.android.apps.photos.content/0/https%3A%2F%2Flh3.googleusercontent.com%2FxXsZw6C7QABlFZbEqzd1c5qjiAAkpQtnlyESHDY9xl4%3Ds0-d

此图像通过云端同步到设备上。

我们从 getContentResolver() 或 CursorLoader 得到这个文件路径

但我们无法将其转换为位图对象

使用 FileInputStream 将这种文件路径转换为位图的任何想法

【问题讨论】:

  • 尝试下载网址lh3.googleusercontent.com/…
  • 是的,你是对的,但我不想通过网络下载图像,因为它存在于我的设备上。如果由于照片应用程序施加的限制而无法从设备中读取图像,那么我将接受您的回答并通过下载图像来实现。

标签: android bitmap


【解决方案1】:

您可以将 FileInputStream 读入一个 byte[],然后执行 BitmapFactory.decodeByteArray(byte[] input param, offset, length of byte[]) 来创建一个位图。

更多详情请参考此链接 - http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeByteArray(byte[],int,int,android.graphics.BitmapFactory.Options)

BitmapFactory 中还有其他选项,您可能想尝试一下,具体取决于您打算做什么。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 2019-12-13
    • 1970-01-01
    • 2020-10-02
    • 2017-09-06
    • 1970-01-01
    相关资源
    最近更新 更多