【问题标题】:pebble bitmap xor or mask?卵石位图异或或掩码?
【发布时间】:2014-11-19 06:40:36
【问题描述】:

在 Pebble 手表上,我试图用文本覆盖位图图层,以便文本在黑色区域上写成白色,在白色区域上写成黑色。

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

如何做到这一点?

我正在使用 C 和 CloudPebble。

林德

【问题讨论】:

  • 我想知道developer.getpebble.com/docs/c/… 模式是否是答案。它适用于组合位图,也许也适用于文本(没有尝试过)。
  • 我查看了 (GcompOp) 但无法弄清楚如何在文本或图形周围没有块状边框的情况下使其工作。最后我编写了自己的例程来完成它。

标签: pebble-sdk cloudpebble


【解决方案1】:

这是一个例行程序。文本层必须在图形层“下方”,然后使用 layer_set_update_proc() 将图形层的更新过程设置为下面的例程。

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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多