首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无PROGMEM的Adafruit库drawBitmap

无PROGMEM的Adafruit库drawBitmap
EN

Stack Overflow用户
提问于 2015-09-05 21:27:52
回答 1查看 3.2K关注 0票数 1

因此,我试图将图像的字节数组放到外部eeprom (c24LC16B)中,并在Adafruit库中使用drawBitmap()函数在Nokia3310LCD上绘制它(带有Adafruit PCD8544库)。但问题是,drawBitmap()只能使用静态字节PROGMEM数组。使用bad,我需要从eeprom读取img数组到缓冲区(字节buf504{};),然后在显示中绘制它。

我尝试了一些在线修改,比如将以下内容添加到Adafruit_GFX.ccp中:

代码语言:javascript
复制
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的字节不是相同的吗?对我的语法也很抱歉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-07 10:12:16

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

只需将其添加到Adafruit_GFX.ccp

代码语言:javascript
复制
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来说

代码语言:javascript
复制
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),

用法:

代码语言:javascript
复制
drawRambitmap(x,y,h,w,color,byte_array_of_img, size_of_array);

代码语言:javascript
复制
drawRambitmap(x,y,h,w,color,background_color,byte_array_of_img, size_of_array);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32417848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档