我们有一个将 jpeg 图像转换为字节数组的 java 代码,如下所示:
BufferedImage bufferimage = ImageIO.read(new File(homePath + "/codebase" + imageLocation));
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageIO.write(bufferimage, "jpg", output );
byte [] data = output.toByteArray();
byte[] imgByteArray = convertFileToByteStream(imagePath, "Image");
map.put("image", imgByteArray);
JSONObject jsonObj = new JSONObject(map);
jsonArray.put(jsonObj);
这是在服务器端,然后将字节数组放入 json 并发送到客户端。
客户端是用 C++ 和 Qt 编写的。那么现在如何从 json 中提取这个字节数组并转换为相同 jpeg 格式的 QImage 呢?
任何帮助将不胜感激!