Transparent buffered bitmap

I wrote the code

        gB = new Gfx.BufferedBitmap({
            :disableTransparency => false,
            :width=>(center - goWidth)*2,
            :height=>(center - goWidth)*2,
            :palette=> [
                Gfx.COLOR_BLACK,
                Gfx.COLOR_WHITE,
                Gfx.COLOR_TRANSPARENT
            ]
        });
        var tdc=gB.getDc();
        tdc.setColor(Gfx.COLOR_TRANSPARENT,Gfx.COLOR_TRANSPARENT);
        tdc.clear();

On the last line  "tdc.clear()", the simulator freezes.

I planned to overlay this over the background so as not to render the background elements in the bitmap. How do I make this work?

  • Former Member
    Former Member over 5 years ago

    What you are attempting to do is not something that has generally been supported. I think the operations you have listed may have been enabled in a recent SDK update, or may be coming in a later update if not. I am not sure why you would be seeing a simulator freeze. 

    A workaround that should work even on older SDKs is to use a placeholder color instead of transparent, clear the buffer with that placeholder, and then re-assign the palette with transparent at that index.

  • could you example the reassign part?

  • Ok,

    I can reassign one of the colors in the fixed color palette.

            var mask = bufferedBitmapFactory(
            {
                :width=>w+w+4,
                :height=>w+w+4,
                :palette=> [
                    $.BGC,
                    Graphics.COLOR_WHITE
                ]
            });
    ... 
            mask.setPalette([
                $.BGC,
                Graphics.COLOR_TRANSPARENT,
            ]);
    
    

    But how do I reassign one of the colors in the full color palette?

    I need to display an image while keeping the image in the background. Since this is done in the native watchface FR965.

            var mask = bufferedBitmapFactory(
            {
                :width=>w+w+4,
                :height=>w+w+4,
            });
    ... 
            ???????????????????
            mask.setPalette([
                $.BGC,
                Graphics.COLOR_TRANSPARENT,
            ]);
            ???????????????????