Complete
over 2 years ago

WERETECH-12048

Fix will be applied to next SDK release.

Devices affected will have firmware updates in a future firmware build.

No more transparency for font background on bufferd bitmap since SDK 4.0

Hi, 

I use a bufferedBitmap with color palette and custom bitmap fonts without antialiasing.

Since SDK 4.0 the font background  is not more transparent. The color is defined before:

dc.setColor(CustomColor, gfx.COLOR_TRANSPARENT);
   

The code is running many years without problem.

I don't understand, what's going wrong with new SDK

  • line 7 in the code should be the following

    bb = Graphics.createBufferedBitmap(opts).get();

  • As  mentioned, the randomness is due to the lack of "COLOR_TRANPARNET" in the palette, so please make sure you have that added.

    That said, as the issue or BufferedBitmap retain the transparent attribute after drawText with transparent bg color, it's mostly by design.

    unlike the screen dc, BufferedBitmap is considered as a bitmap and clear it (or draw text ) with transparent bg color will result in the pixels in question area to be replaced by "transparent" pixel explicitly. So later on, when the BufferedBitmap is blit on top of the screen dc, we can though the transparent area in the BufferedBitmap.

    // fill screen with yellow bg color
    dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_YELLOW);
    dc.clear();
    var bb;
    var opts = {:width=>dc.getWidth(), :height=>dc.getHeight(), :palette=>[Graphics.COLOR_BLACK, Graphics.COLOR_RED, Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT]};
    if(Graphics has :createBufferedBitmap) {
        bb = Graphics.createBufferedBitmap();
    } else {
        bb = new Graphics.BufferedBitmap(opts);
    }
    var bbDc = bb.getDc();
    bbDc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_RED);
    bbDc.clear();
    // set bg to transparent
    bbDc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
    // draw text with transparent bg color will result in the text area to be
    // filled with "transparent" pixels
    // Note: _font must be 1-bpp, non-anti alias font
    bbDc.drawText(dc.getWidth()/2, dc.getHeight()/2, _font, "1234", Graphics.TEXT_JUSTIFY_CENTER);
    dc.drawBitmap(0, 0, bb);

    Here is the code I used to test, please feel free to play with it and let me know if this caused issues that you are not expecting.

  • The same problem with "MARQ Athlele" watchface by Bine8x8 on Fenix 7x Sapphire Solar (v7,20)

  • More than three months have passed. Ticket has been created, but the problem has not been solved!!!

    I am asked by the user of my developments. I'll redirect their wrath to Garmin.

    Ugliness!!!

  • This might be what is happening for me here - I thought that drawing the text cuts out its rectangle, but it might actually just set the pixels in a target bitmap to transparent (which is equally bad though): forums.garmin.com/.../how-to-draw-text-with-transparent-background-into-palleted-bitmap-in-sdk4