1

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

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

如何才能做到这一点?

我正在使用 C 和 CloudPebble。

林德

4

1 回答 1

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);
}
于 2015-01-23T01:20:23.383 回答