我不知道,为什么我从 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 网络服务给出的图像位置。