Complete
over 2 years ago

How to draw text with transparent background into palleted bitmap in SDK4?

Hello, I seem to have run into a thing that worked fine in SDK3 and doesn't work in SDK4.

I was having a paletted bitmap, and I have drawn some background into it, and then I wanted to add text.

The bitmap is defined like this:

var bitmapOptions = {
	:width => w,
	:height => h,
	:palette => [
		// in sdk 4, we need to explicitly add transparent color to palette?
		Gfx.COLOR_TRANSPARENT,
		// TODO: create palette from theme
		Gfx.COLOR_WHITE,
		Gfx.COLOR_LT_GRAY,
		Gfx.COLOR_DK_GRAY,
		Gfx.COLOR_BLACK,
		Gfx.COLOR_RED,
		Gfx.COLOR_DK_RED,
		Gfx.COLOR_BLUE,
		Gfx.COLOR_DK_BLUE,
		Gfx.COLOR_YELLOW,
		Gfx.COLOR_ORANGE,
		Gfx.COLOR_GREEN,
		Gfx.COLOR_DK_GREEN
	]
}

if (Graphics has :createBufferedBitmap) {
	var weatherBitmapInGraphicsPool = Gfx.createBufferedBitmap(bitmapOptions);
	weatherBitmap = weatherBitmapInGraphicsPool.get();
} else {
	weatherBitmap = new Gfx.BufferedBitmap(bitmapOptions);
}

I then draw a text from a non-antialiased bitmap font into it:

dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT);
dc.drawText(x, y, font, text, Gfx.TEXT_JUSTIFY_CENTER);

In SDK 3 this has drawn a red text over the image.

In SDK 4 this draws a text on a solid black background, so the result looks really ugly.

I don't want to have a bitmap with full alpha channel, as it's rather large and barely fits to RAM, is there a way I could get back the SDK3 behavior?

I tried the new dc.setStroke(0xFFFF0000) and dc.setFill(0x00000000) methods, but they have absolutely no effect on my paletted bitmap at all:

dc.setColor(Gfx.COLOR_YELLOW, Gfx.COLOR_ORANGE);
dc.setStroke(0xFFFF0000);
dc.setFill(0x00000000);
dc.drawText(x, y, font, text, ...);

The above code draws yellow text on orange background into my paletted bitmap.

  • My watch is the fenix 6 and it doesn't not have that function available yet. I am using the bufferedBitmap without any palette only the system palette and having issues with drawing custom fonts with transparency

  • Yes, remove palette in bitmap option, if has createdufferedbitmap

  • I am also having this issue, please can we have any information on the status of this?

  • My watchface is very old and it was working well.

    I have changed for SDK 4 for the fenix 7, venu 2 and Epix Gen 2 models

    But now, all my texts with a transparent background are not sent correctly in the buffered bitmap

    This happens all the time for all models with buffered bitmap on the simulator, and I think only on the 4.0 for real devices 

    On the above picture, my watch background is a personnal font with 1 character, written with drawtext and transparent background, and the month (Fev in french)  is written also with transparent background, into a rectangle filled with black. The rectangle is OK, but not the text

    Could you confirm the bug is real and the fix is in progress ?

  • Transparent pixels should not be getting rendered.