UTFT_tinyFAT Load Bitmap into Array

Has anyone written a routine to load an image from an SD card into an array?

What I want is something like the “loadBitmap” function from the UTFT_tinyFAT library except I want to store the image in an array instead of displaying it directly on the TFT display. Once I have all the images from the flash stored in arrays, I would use the “drawBitmap” function from the UTFT library to minipulate which image(s)/array(s) to put where on the screen.

Any ideas?

thank you in advance.

Calculate the size of the array? Will it fit on your Arduino?


Yes, there are 8 arrays (0xE10 each) on an Arduino Mega 2560. If I hard code these arrays in the program, it compiles to a total size of 181,846 (of 258,048 bytes) with program and libraries and everything so I know it fits. The problem is, at this size the program won't actually upload to the Mega; it just grinds on it for about 5 minutes and eventually times out.

I figure if I have the program just pull in the arrays from the SD, and then use the arrays as I am now it will compile and upload fine and then if I ever want to change the graphics, I can just update the images on the SD and not have to re-compile the program).

Thanks in advance for your help,

The size reported by the IDE does not include the the data space /RAM usage. What 8x0xe10 (converting it to decimal would help) is much greater than the available RAM.

If I hard code these arrays in the program

Are you using progmem?.


You have a program "ImageConverter565" in the UTFT/Tools folder, you can choose to save the image as a .c file that contain the progmem array.

Just saying, I'm currently writing a plugin for Paint.NET that does the same thing (and much more, with a UTFT addon). Release soon in my sig :wink:

The images are 60x60 which puts it at 3600 bytes/image (0xE10) for 16 images = 57.6k bytes. (sorry I had put 8 images in the last post; there is an ON and an OFF image for each of the 8 so there are 16 total)

Yes, I am using ImageConverter 565 to create the .c files for each image. Then I am then loading the .c files as external variables (see here).

extern unsigned int brake_off[0xE10];
extern unsigned int brake_on[0xE10];
extern unsigned int choke_off[0xE10];
extern unsigned int choke_on[0xE10];
extern unsigned int door_off[0xE10];
extern unsigned int door_on[0xE10];
extern unsigned int engine_off[0xE10];
extern unsigned int engine_on[0xE10];
extern unsigned int hatch_off[0xE10];
extern unsigned int hatch_on[0xE10];
extern unsigned int overdrive_off[0xE10];
extern unsigned int overdrive_on[0xE10];
extern unsigned int security_off[0xE10];
extern unsigned int security_on[0xE10];

Next, I am loading a pointer to those external variables from my own class as shown here:


Finally, I use the drawButmap function from the UTFTtf library to draw the image from the array on the screen.

myGLCD.drawBitmap (LeftX, TopY, SizeX, SizeY, _ButtonImages[IndexOfImage2Display]);

With a couple images, this all works, but with all 16 it just locks up during upload (as previously stated). Isn't there a better way? Isn't loading the images from the SD a better option for populating the arrays?

Why don’t you just use UTFT_TinyFAT?

I could use that to load an image directly to the screen, but for a control panel interface where the images will toggle back and forth, I was going to try and avoid the delay of reading images from flash every time an image changes. My thought was that during initialization, I would just load the images into arrays and then just use “drawBitmap” to write the image from the arrays to the screen.

Starting with the “loadBitmap” function that you mention, I took a shot at a routine to load the bitmap to an array instead of the screen but I haven’t tested it yet. Here is my guess at what the function could look like.

word UTFTtf::loadBitmapArr(char filename, unsigned int bitmaparray[]){
filename = filename of “raw” file to load from SD card
bitmaparray = array to put data into
int res;
int cx, cy, cp;
word temp, result;
byte r,g,b;

res=file.openFile(filename, FILEMODE_BINARY);
if (res==NO_ERROR)
cbi(P_CS, B_CS);
while (result==512)

for (int i=0; i<result; i+=1)
// bitmaparray_=file.buffer*;_
_ break;
sbi(P_CS, B_CS);
_ return 0;
* {
return res;

Tell us what you think "extern" does, all it means is that it will be declared in another file, it does not mean put the data space on the SD card or in progmem so you still use up your 8k of ram.


I don't know where you're coming from... the code I posted shows the declaration of the external variables, and then the storing of those externs in arrays. I pass those arrays to the "drawBitmap" function to display the data. Now that the size of the images has grown pretty close to the available memory, the compiler is unable to upload the program to the device (even though it compiles fine without upload). To work around this, I want to load the arrays from SD memory instead of grabbing them externally.

Do you know how I can do that?

Thank You

Programs of the avr's split in two program in flash/eeprom and data in SRAM. Your arrays are in SRAM of which you have only 8k
to my count you have 14 arrays of 3600 bytes and thats a lot more than 8k. Externs still go in RAM!

Do you know how I can do that?

You cant. You cant copy them hrom the SD card or any where else to Sram that you do not have!.


Ahh, sorry I finally understood what you want to do. I should stop smoking my garden xD. Yeah you basically can't do that with an arduino because not enough memory... Also an RGB565 image of size 60x60 is not 3600 bytes but twice more because one pixel color is 2 bytes.

Then my UTFT addon, when ready, could really interest you, for some simple graphic images where the colors repeat a lot (like for example a button with horizontal gradient) the size can be reduced a lot, meaning that it will be much faster to read it from the SD. It produces a filesize almost like .png, and in many cases much smaller, and should be very quick to draw on the screen but I haven't tested that yet.

Thanks soo much to everyone; I had already spent way too much time trying to write the routine, which could never work. I'll try just loading from Flash and see how fast it ends up being.


There are at least two other ways around your problem.

A. Use program memory this creates the arrays in the flash/eeprom of the arduino and not in ram for details look in the playground. this requires that you convert the bmp in code which the IDE when builds in for you. guix offered to code to convert the bmp files. See the section on storage in the playground or/and google “progmem”.

B. Take look at this for the Megas http://ruggedcircuits.com/html/megaram.html