Is it possible to fill a string or number with two colors?

Former Member
Former Member

For example, let's say I have the text "Hi". Can I paint the top 30% red and the bottom 70% green?

  • Here's a very simple example of dong two color, that will work on any CIQ device:

    The code:

    //clear screen
    dc.setColor(Gfx.COLOR_BLACK,Gfx.COLOR_BLACK);
    dc.clear();
    //define stuff
    var str="1234";
    var f=Gfx.FONT_MEDIUM;
    var fH=dc.getFontHeight(f);
    var sW=dc.getTextWidthInPixels(str,f);
    var x=100,y=100;
    //do the draws
    //red box
    dc.setColor(Gfx.COLOR_RED,Gfx.COLOR_TRANSPARENT);
    dc.fillRectangle(x, y+1, sW,fh+1);
    //green box at 50%
    dc.setColor(Gfx.COLOR_GREEN,Gfx.COLOR_TRANSPARENT);
    dc.fillRectangle(x, y+fH*.5-1, sW,fh*.5);
    //overlay text.
    dc.setColor(Gfx.COLOR_TRANSPARENT,Gfx.COLOR_BLACK);
    dc.drawText(x,y,f,str,Gfx.TEXT_JUSTIFY_LEFT);

    The output:

  • Former Member
    Former Member over 5 years ago in reply to jim_m_58

    I got it working. Thanks!

  • Any ideas on how to achieve a smooth gradient like this one where it fades from one color to another? Are there any newer API methods that can do this?