gpt4 book ai didi

java - 我想将jpg图像转换为字节数组并将字节数组作为命令发送给java中的阅读器

转载 作者:行者123 更新时间:2023-12-01 13:38:37 24 4
gpt4 key购买 nike

我正在我的项目中使用它。我想将图像(小于 5kb)转换为字节数组,然后将其发送到卡,并等待响应。一旦我得到响应,我想再次将其更改为字节数组,而无需响应位(即 9000)并希望恢复原始图像

最佳答案

要将图像转换为字节数组,您可以执行以下操作:

ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(img, "PNG", out); // or "JPG", or whatever
byte[] bytes = out.toByteArray();

将字节数组转换为图像:

ByteArrayInputStream in = new ByteArrayInputStream(bytes);
BufferedImage img = ImageIO.read(in);

至于读卡器,这取决于......

关于java - 我想将jpg图像转换为字节数组并将字节数组作为命令发送给java中的阅读器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21038455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com