首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pebble位图xor或mask?

pebble位图xor或mask?
EN

Stack Overflow用户
提问于 2014-11-19 14:40:37
回答 1查看 219关注 0票数 1

在Pebble watch上,我正在尝试用文本覆盖一个位图图层,这样文本就会在黑色区域上写成白色,在白色区域上写出黑色。

在其他环境中,我会使用XOR操作来实现这一点,或者创建一个掩码,并在屏蔽掉我不想覆盖的内容后执行几次写入。我在Pebble图形库中没有看到XOR图形运算符或掩码运算符。

如何做到这一点?

我使用的是C和CloudPebble。

Lynd

EN

回答 1

Stack Overflow用户

发布于 2015-01-23 09:20:23

下面是一个执行此操作的例程。文本层必须在图形层下,然后使用layer_set_update_proc()将图形层的更新过程设置为下面的例程。

代码语言:javascript
复制
static void bitmapLayerUpdate(struct Layer *layer, GContext *ctx){
  GBitmap *framebuffer;
  const GBitmap *graphic = bitmap_layer_get_bitmap((BitmapLayer *)layer);
  int height;
  uint32_t finalBits;
  uint32_t *bfr, *bitmap;

  framebuffer = graphics_capture_frame_buffer(ctx);
  if (framebuffer == NULL){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "capture frame buffer failed!!");
  } else {
//    APP_LOG(APP_LOG_LEVEL_DEBUG, "capture frame buffer succeeded");
  }
  height = graphic->bounds.size.h;

  for (int yindex =0; yindex < height; yindex++){
    for ( unsigned int xindex = 0; xindex < (graphic->row_size_bytes); xindex+=4){
      bfr = (uint32_t*)((framebuffer->addr)+(yindex * framebuffer->row_size_bytes)+xindex);
      bitmap = (uint32_t*)((graphic->addr)+(yindex * graphic->row_size_bytes)+xindex);
      finalBits = *bitmap ^ *bfr;
      // APP_LOG(APP_LOG_LEVEL_DEBUG, "bfr: %0x, bitmsp: %0x, finalBits: %x", (unsigned int)bfr, (unsigned int)bitmap, finalBits );

      *bfr = finalBits;
    }
  }
  graphics_release_frame_buffer(ctx, framebuffer);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27010554

复制
相关文章

相似问题

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