1

我不知道,为什么我从 BitmapFactory.decodeFile(String imagePath) 方法中得到空值。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 网络服务给出的图像位置。

4

1 回答 1

4

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

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

于 2012-12-07T16:40:09.053 回答