gpt4 book ai didi

android - BitmapFactory.decodeFile(String imagePath) 即使图像存在也返回 null

转载 作者:行者123 更新时间:2023-11-29 16:10:34 24 4
gpt4 key购买 nike

我不知道,为什么我从 BitmapFactory.decodeFile(String imagePath) 方法中得到 null。imagePath 是完美的。代码在下面。

public static byte[] imageToByteArray(String imagePath){
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG , 100 , byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}

imagePath 是互联网特定路径。我在这里使用 google place api,imagePath 是 google 网络服务提供的图像位置。

最佳答案

decodeFile用于从本地文件系统获取Bitmap

Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.

从互联网上获取Bitmap

Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream());

不要忘记在后台线程中运行上面的行。

关于android - BitmapFactory.decodeFile(String imagePath) 即使图像存在也返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767199/

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