1

所以我试图将图像的字节数组放入外部 eeprom (c24LC16B) 并使用 Adafruit gfx 库中的 drawBitmap() 函数在诺基亚 3310 LCD 上绘制它(使用 Adafruit PCD8544 库)。但问题是,drawBitmap() 只能使用静态字节 PROGMEM 数组。不好,我需要将 img 数组从 eeprom 读取到缓冲区(字节 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);
    }
  }
}

但它仍然只显示垃圾

那么为什么对 PROGMEM 和普通数组有这么大的影响呢?PROGMEM 和 SRAM 中的字节不一样吗? 也对不起我的语法。

4

1 回答 1

2

我做的 !我所要做的就是编写我自己的函数!=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);
于 2015-09-07T10:12:16.347 回答