简体   繁体   English

没有PROGMEM的Adafruit gfx库drawBitmap

[英]Adafruit gfx library drawBitmap without PROGMEM

So im trying to put byte array of image in external eeprom (c24LC16B) and use drawBitmap() function in Adafruit gfx library to draw it on Nokia 3310 LCD (with Adafruit PCD8544 library). 因此,我试图将图像的字节数组放入外部eeprom(c24LC16B)中,并使用Adafruit gfx库中的drawBitmap()函数在诺基亚3310 LCD(带有Adafruit PCD8544库)上进行绘制。 But the problem is, that the drawBitmap() can use only static byte PROGMEM array. 但是问题是,drawBitmap()只能使用静态字节PROGMEM数组。 With is bad, I need to read the img array from eeprom to buffer (byte buf[504]{}; ) and then draw it on display. With不好,我需要从eeprom读取img数组到缓冲区(字节buf [504] {};),然后在显示器上绘制它。

i tried some modifications, that i found online, like add this to the Adafruit_GFX.ccp: 我尝试了一些在网上找到的修改,例如将其添加到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);
    }
  }
}

but it still only displayed rubbish 但它仍然只显示垃圾

So why is there such big deal about PROGMEM and normal arrays ? 那么,为什么PROGMEM和普通数组有这么大的问题呢? Isnt byte from PROGMEM and from SRAM the same ? 来自PROGMEM和SRAM的字节不相同吗? Also sorry for my grammar. 也为我的语法感到抱歉。

i did it ! 我做的 ! All i have to do it was to write my own function ! 我要做的就是编写自己的函数! =D = d

just add this to the Adafruit_GFX.ccp 只需将其添加到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++;
      }
    }
  }
}

and this for Adafruit_GFX.h 这是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),

usage: 用法:

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

or 要么

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