Adafruit gfx库绘制位图没有程序

Adafruit gfx library drawBitmap without PROGMEM

本文关键字:程序 位图 绘制 gfx Adafruit      更新时间:2023-10-16

所以我试图把字节数组的图像在外部eeprom (c24LC16B)和使用drawBitmap()函数在Adafruit gfx库绘制它在诺基亚3310 LCD(与Adafruit PCD8544库)。但问题是,drawBitmap()只能使用静态字节程序数组。我需要从eeprom读取img数组到缓冲区(字节buf[504]{};)然后把它画出来展示。

我尝试了一些修改,我在网上找到的,比如把这个添加到Adafruit_GFX.ccp:

void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
                  uint8_t *bitmap, int16_t w, int16_t h,
                  uint16_t color) {
  int16_t i, j, byteWidth = (w + 7) / 8;
  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if(bitRead(bitmap[j], 7-i))  
        drawPixel(x+i, y+j, color);
    }
  }
}

但它仍然只显示垃圾

那么为什么程序和普通数组有这么大的区别呢?字节从程序和从SRAM是一样的吗?也为我的语法感到抱歉

我做到了!我所要做的就是写我自己的函数!= D

请将此添加到Adafruit_GFX.ccp

void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize) {
  int pozX = pozXi;
  int pozY = pozYi;
  for (int x = 0; x < mapSize; x++) {
    for (byte y = 0; y < 8; y++) {
      byte dummy = bitmap[x] << y;
      if (dummy >= 128) {
        drawPixel(pozX, pozY, color);
      }
      else {
        drawPixel(pozX, pozY, bg);
      }
      pozX++;
      if (pozX == w + pozXi) {
        pozX = pozXi;
        pozY++;
      }
    }
  }
}
void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize) {
  int pozX = pozXi;
  int pozY = pozYi;
  for (int x = 0; x < mapSize; x++) {
    for (byte y = 0; y < 8; y++) {
      byte dummy = bitmap[x] << y;
      if (dummy >= 128) {
        drawPixel(pozX, pozY, color);
      }
      pozX++;
      if (pozX == w + pozXi) {
        pozX = pozXi;
        pozY++;
      }
    }
  }
}

和Adafruit_GFX.h

drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize),
drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize),

用法:

drawRambitmap(x,y,h,w,color,byte_array_of_img, size_of_array);

drawRambitmap(x,y,h,w,color,background_color,byte_array_of_img, size_of_array);