Invert Bitmap colors preserving transparency

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Invert Bitmap colors preserving transparency

      Hello, I have a small issue managing a transparent bitmap.

      Basically I have a bitmap with transparency with a white logo and I use it on a black background (default "dark" mode).
      (This logo has to be also touchable so it is created as a button with its own callback, the parent of the button is the background.)

      If I switch to the "light mode" the background will be white and I want the logo to be black preserving its transparency.

      I've tried something like this in the WM_PAINT case of the button callback:

      Source Code

      1. static void _OnPaintLogo(BUTTON_Handle hObj)
      2. {
      3. GUI_RECT *pRect;
      4. GUI_DrawBitmap(g_sGUIStartup.Buttons[BTN_CUSTOMERLOGO_IDX].pCurrImage, 0, 0);
      5. if (g_App.Settings.GuiColorMode == GUI_TYPE_COLOR_MODE_LIGHT)
      6. {
      7. WM_SetHasTrans(hObj);
      8. WM_GetClientRectEx(hObj, pRect);
      9. GUI_InvertRect(pRect->x0, pRect->y0, pRect->x1, pRect->y1);
      10. }
      11. }
      Display All
      And this inverts the colors of the bitmap but does not preserves transparency as the result is a black logo with a black background.
      I suppose it is like that because the button's parent is the background which is white.
      I've tried to set to white the background again after the GUI_InvertRect call but it gives no effect.

      Any suggestion on how to make it work?

      Thank you,
      Mark
    • Hi,

      If the background is just plain black you could remove the transaprency flag of the button and fill it with black. Then draw the bitmap.

      If the mode switches from dark to bright simply fill the background window with white and in the callback of the button call GUI_InvertRect() (but still fill the button with black, it will get white).

      Take a look into the example attached.

      Regards,
      Sven
      Files
      • InvertColor.zip

        (12.17 kB, downloaded 691 times, last: )
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.