实则就是把图片文件读取成byte数组 ,然后再转成16进制数组数据
/**
*
* @param bytes
* @param filePath String imagePth = “C:UsersAdministratorDesktop无标题.jpg”;
*/
public static void jpgToFileBytes4Esp32(String filePath){
try {
BufferedImage bufferedImage = ImageIO.read(new File(filePath));
//ByteArrayOutputStream outputStream =new ByteArrayOutputStream();
byte[] bts = FileUtil.getBytes(imagePth);
for(int i=0;i<bts.length;i++){
int value = (int)bts[i];
if(value<0){
value+=256;
}else{
}
System.out.print("0x"+Integer.toHexString
(value)+",");
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void hexByte2Jpg(){
File file =new File("d:/newjpg.jpg");
try {
FileOutputStream outputStream =new FileOutputStream(file);
outputStream.write(newjpgary);
} catch (IOException e) {
e.printStackTrace();
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...



