我正在尝试读取平台站点上生成的位图,
这是我用来在 android 中生成字节数组的代码:
ByteBuffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(byteBuffer);
return byteBuffer.array();
当我尝试使用图像库对其进行解码时,它失败了(飞镖代码):
Image img = decodeBmp(bitmapData);
在 null 上调用了方法“getBytes”。
位图数据不为空,看起来适合我
如果我将android端的图像压缩为png或jpg而不是decodeImage(或-Png或-Jpg)有效
,但我不想使用bitmap.compress
此代码将适用于compress
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bufferedBmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] imageData = baos.toByteArray();
return imageData;