How do I create an image from its text representation?

If you add an image somewhere in the Lazarus IDE and save the project, it will be saved as text in the project's .lfm file. Here is an example:

5A000000424D5A00000000000000360000002800000003000000030000000100
200000000000240000006400000064000000000000000000000021FF00FF6E00
FFFF00D8FFFFCC483FFF000000FFFFFF00FFFF0048FF241CEDFFFFFFFFFF

I need to create an image file in .png, based on such data. To begin with, I was trying to extract the pixel colors to create images pixel-by-pixel. I was able to find the color codes in this text, even though they were reversed. But even if I can extract all the color codes correctly, I don't know how save them to a file. For the solution, I use Python 3.4. I think that regular expressions will help in the solution. The image above has the size of 3x3 pixels, where each pixel has its own color, and contains the following colors (hex):

4800FF, ED1C24, FFFFFF,
3F48CC, 000000, 00FFFF,
00FF21, FF006E, FFD800
Author: AndroID, 2020-09-10