PNG and BUTTON_SetBitmap

  • PNG and BUTTON_SetBitmap

    Hi,

    I need to display a PNG (with transparency) image in a button.
    Using a bitmap works without problem, but how can I use a PNG at this point (e.g. uncompressing it before to bitmap and)?
  • Hi Frost,

    There are several ways of displaying a PNG on a Button.

    The way how to do it depends on your requirements.

    The easiest way is to convert the PNG into an emWin bitmap format (not BMP) with the BitmapConverter and simply copy the output (if a c-file is choosen as output) into your code.
    The emWin bitmap format is the fastest way to display an image and is quite easy to handle. I would recommend this way.

    Further you can overwrite the callback of the button and use GUI_PNG_Draw() (or one of the other PNG drawing functions) to display the image.
    The PNG library doesn't come with emWin you have to download it under the link below.
    segger.com/link/emwin_png.zip

    Instead of overwriting the callback you can use a custom skinning routine and draw the PNG there.

    Regards,
    Sven
    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.
  • Dear Sven,

    thanks for the reply.
    The first method will require more persist memory than saving the PNG directly, whereas the second option might make the GUI much slower, since the PNG decompression has to be done several times (depending on how often the callback is executed).

    So I was wondering about a further method, which decompress the PNG into RAM only once on startup and then loads it from there when needed?
  • Hi Frost,

    You could draw the PNG into a memory device and use this for displaying the image.
    Or, convert the PNG into a streamed bitmap, copy it into RAM before drawing and free the memory when it's not required anymore.

    Regards,
    Sven
    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.
  • In the meanwhile I found out, that the BitmapConverter tool supports a compressed bitmap format, which is useful for icons or image where you typically have less colors or areas with the same color. Comparing the space requirement it is nearly as low as PNG, therefore I will use this format!



    Thanks,
    Johannes