This section describes how dynamic bitmaps can be used to create applications where some of the graphic content is read from files or other input at runtime. The dynamic bitmaps can be used to show e.g. image files from an SD-card.
Recall that standard bitmaps are compiled into the application and therefore must be available at compile time. The Dynamic Bitmap feature allows you to read images from files at runtime, or even download images through an internet connection.
Here we will see how to use a BMP loader to load pixels from a Windows BMP file. The code for the loader is later in the article.
Insert first an Image widget in the view. This widget will show the BMP:
Load the image date in setupScreen:
Here is the code for a simple BMP file loader. It only supports 24bpp BMP files. You may have to adjust the file system calls to match your system.
This code is for illustrative purposes. A more optimal reader for RGB888 can read directly from the file to the dynamic bitmap memory (remember to skip the row padding). The reader above reads 10 pixels from the BMP file to a temporary buffer. The pixels are then copied to the bitmap while converting to the correct format.
Before you can create and use dynamic bitmaps you must configure TouchGFX. It is a prerequisite to provide a buffer and the maximum number of dynamic bitmaps (also for the simulator).
Here is an example for STM32F7xx where we allocate a buffer in external RAM: We wish to load and show a 24-bit bitmap of size 320x240. The memory requirement is thus 320x240x3 = 230400. We also need a little space for bookkeeping, so we allocate 232000 bytes for the buffer.
The final argument is the maximum number of dynamic bitmaps, so adjust this according to your needs.
A JPEG File Loader example can be found here which shows how to use LibJPEG to use JPEG-files. It uses a JPEGLoader class similar to the above BMPFileLoader.