esp32 把jpg转成数组供esp32显示

内容分享4小时前发布
0 0 0

实则就是把图片文件读取成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();
    }

}

© 版权声明

相关文章

暂无评论

none
暂无评论...