将PNG文件转换为不带标题的位图

问题描述

我需要为Arduino设备准备一个位图源流(带有电子墨水显示器)。数据来自PNG文件。我需要一个没有标题的“原始”图像数据。图像每个像素(屏幕上的黑色或白色像素)仅1和0。不幸的是,我不知道如何删除标题并将PNG文件转换为位图。这是我现在使用的代码(NodeJS):

const http = require('http');
const fs = require('fs');

const server = http.createServer(function(req,res) {
  res.setHeader('content-type','application/octet-stream');

  fs.readFile('sample.png',function(err,data) {
    res.end(data);
  });
});

server.listen(3000);

当我使用BMP文件作为源文件时,它几乎可以正常工作,但是我需要使用PNG文件。

这是我在Arduino上读取流的方式:

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
ESP8266WiFiMulti WiFiMulti;

#include <GxEPD.h>
#define ROTATION 1
#include <GxGDEW0583T7/GxGDEW0583T7.cpp>
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>

GxIO_Class io(SPI,5,2);
GxEPD_Class display(io,2,12);

#define X_RES 448
#define Y_RES 600

void displayImage() {
      uint32_t cursor = 0;
      uint8_t eightPixels;
      boolean initialized = false;
      int len = http.getSize();
      uint8_t buff[256] = { 0 };

      WiFiClient * stream = http.getStreamPtr();

      while(http.connected() && (len > 0 || len == -1)) {
        size_t size = stream->available();

        if(size) {
          int c = stream->readBytes(buff,((size > sizeof(buff)) ? sizeof(buff) : size));

          for (int offset = 0; offset < c; offset++) {
            if (!initialized) {
              initialized = true;
              display.init();
              display.setRotation(1);
            }

            eightPixels = buff[offset];

            if (cursor < X_RES*Y_RES) {
              for (uint8_t i = 0; i < 8; i++) {
                if ((eightPixels >> (7-i)) & 0x01){
                  display.drawPixel((cursor+i)%X_RES,(cursor+i)/X_RES,GxEPD_BLACK);
                }
              }
              cursor+=8;
            }
          }

          if(len > 0) {
            len -= c;
          }
        }
        delay(1);
      }
      display.update();
    }
}

如果您能以某种方式帮助我,我将非常感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...