簡體   English   中英

沒有PROGMEM的Adafruit gfx庫drawBitmap

[英]Adafruit gfx library drawBitmap without PROGMEM

因此,我試圖將圖像的字節數組放入外部eeprom(c24LC16B)中,並使用Adafruit gfx庫中的drawBitmap()函數在諾基亞3310 LCD(帶有Adafruit PCD8544庫)上進行繪制。 但是問題是,drawBitmap()只能使用靜態字節PROGMEM數組。 With不好,我需要從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);
    }
  }
}

但它仍然只顯示垃圾

那么,為什么PROGMEM和普通數組有這么大的問題呢? 來自PROGMEM和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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM