android - Dart/Flutter 图像库解码位图失败
问题描述
我正在尝试读取平台站点上生成的位图,
这是我用来在 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;
解决方案
推荐阅读
- prolog - prolog 中的事实按 3 个变量分组
- hive - 查找非十六进制格式的数据
- javascript - 删除会话存储 - 购物车项目
- php - 可以获得表单令牌 - Symfony 4
- typescript - 如何在接口的重写方法中访问当前类变量,该方法是使用当前类中的 setter 设置的
- vue.js - 注册并使用 Vue-Multiselect 组件
- ios - 容器在 IOS 和 Android 上的高度不同
- firebase - 如何将我的文档字段放入 Firestore 中的模型字段
- postgresql - 参考同一选择查询中的其他别名列标题
- angular - ERROR 错误:无法设置未定义的属性“分页器”