试图用文本掩盖APNG背景 [英] Trying to mask APNG background with text

查看:168
本文介绍了试图用文本掩盖APNG背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Pebble示例 APNG并尝试使用透明文本对其进行遮罩,因此位图将仅显示文本,但是无论我尝试使用哪种遮罩/复合模式,位图都将显示为黑白(原始动画为彩色,如果我使用原始动画,则为彩色)不要画文字)

I am taking Pebble example of working with APNG and trying to mask it with transparent text, so bitmap will show only thru text, but no matter what mask/composite mode I try, bitmap is shown as black-and-white (original animation is in color and shows in color if I don't draw text)

这是我在回调SP中用于绘制文本的图层的示例代码:

Here's a sample code I use in callback SP for the layer that draws text:

//creating background and text
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, GRect(0, 0, 144, 168), 0, GCornerNone);
graphics_context_set_text_color(ctx, GColorWhite);
graphics_draw_text(ctx, "08:39", fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49), GRect(0,50,144,118), GTextOverflowModeFill, GTextAlignmentCenter, NULL);

//drawing bitmap (extracted from bitmap_sequence elsewhere) 
graphics_context_set_compositing_mode(ctx, GCompOpClear);
graphics_draw_bitmap_in_rect(ctx, s_bitmap, GRect(0,0,144,168));

有什么想法可以让实际的颜色位图显示出来吗?

Any idea how to have actual color bitmap to show thru?

推荐答案

好,我终于管理好了,但不确定这是否是最好的方法.我基本上是捕获当前层的帧缓冲区,然后遍历每个像素,逐字节地复制源位图,但仅限遇到白色像素的情况:

Ok, I finally managed it but not sure if this is the best way. I basically capture framebuffer of current layer and then loop thru every pixel, copying there source bitmap byte by byte, but only when white pixels are encountered:

GBitmap *fb = graphics_capture_frame_buffer_format(ctx, GBitmapFormat8Bit);

uint8_t *fb_data =  gbitmap_get_data(fb);
uint8_t *anim_data =  gbitmap_get_data(s_bitmap);

for (int i=0; i < 144*168; i++) {
    if (fb_data[i] == 255) {
       fb_data[i] = anim_data[i];
    }
}

也可以进行优化.

这篇关于试图用文本掩盖APNG背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆