image2cpp Utility
image2cpp is a simple tool to change images into byte arrays
https://javl.github.io/image2cpp/
I took an image of a TS1000 and scaled it in GIMP to 256 pixes wide and saved it with filename TS1000-256w. I intentionally left a little white on all sides of the image.
I opened the image2pp Utiltiey at https://javl.github.io/image2cpp/ a at step
- Select image: , I uploaded the image. When I uploaded the image, it's dimensions were automatically filled in in step 2, and the image was previewed in Step3
- Image Settings The Utility filled in my image dimensions, in this case 256 x 267
I left all the defaults in this step - Preview: The preview automatically filled in when I uploaded the image.
- Output:
Code Output Format: Arduino
Identifier/Prefix: epd_bitmap_
Draw mode: Horizontal 1 bit per pixel - I clicked Generate Code and the code appeared in the box
Let's examaine the code.
The first line starts with // which in C is taken as a comment line. It is just showing the images filename less it's extenion. In this case my extension was .gif, and this is followed my my image dimensions
// 'TS1000-256w', 256x267px
const unsigned char epd_bitmap_TS1000_256w [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
sdfsdfsdf
The last 9 lines of code are
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 8560)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_TS1000_256w
};
Now, if we take a look at the image file bitmap.h, that our example file print_bitmap.ino uses, here is what we have:
const unsigned char logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
[many skipped lines]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
sdfsdf
So to use the file produced by iamge2cpp in the manner that we have produced it...
Edit #1 we can optionally delete the first line comment but we can also keep if we want to.
Edit #2 Now let's examine the first line of the sample bitmap.h program which defines an array of unsigned characters.
It sets the name of the array to logo, and the PROGMEM command designates this to be stored in
second line const unsigned char epd_bitmap_TS1000_256w [] PROGMEM = {
Edit #3--- we can simply delete the code at the end starting with // Array
---
The Arduino UNO has only 32K bytes of Flash memory and 2K bytes of SRAM.
Read about PROGMEM here: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/