其实就是把图片文件读取成byte数组 ,然后再转成16进制数组数据
/**
*
* @param bytes
* @param filePath String imagePth = "C:\Users\Administrator\Desktop\无标题.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();
}
}
网友评论