Just for the fun of it:
This Python script reads SVGs created with inkscape (only tested with a few ...
) and creates C++ statements that can be copied into Arduino sketches. It uses the function tft.color565() to convert from 24 Bit (888) to the 16 Bit (565) color format of the ILI9341 display.
#!/usr/bin/python3
from xml.dom import minidom
svg_file = 'inkscape.svg'
doc = minidom.parse(svg_file)
def isFilled(line):
if 'fill:none' in line:
return False
else:
return True
def getFillColor(line):
line = line.upper()
red = '(0x'+line[6:8]
green = ',0x'+line[8:10]
blue = ',0x'+line[10:12]+')'
return 'tft.color565'+red+green+blue
def getStrokeColor(line):
p = line.find('stroke:')+8
line = line.upper()
red = '(0x'+line[p:p+2]
green = ',0x'+line[p+2:p+4]
blue = ',0x'+line[p+4:p+6]+')'
return 'tft.color565'+red+green+blue
def roundCoord(coord):
return round(float(coord))
rects = doc.getElementsByTagName('rect')
for rect in rects:
x = roundCoord(rect.attributes['x'].value)
y = roundCoord(rect.attributes['y'].value)
w = roundCoord(rect.attributes['width'].value)
h = roundCoord(rect.attributes['height'].value)
c = rect.attributes['style'].value
if isFilled(c):
cl = getFillColor(c)
print('tft.fillRect(',x,',',y,',',w,',',h,',',cl,');')
else:
cl = getStrokeColor(c)
print('tft.drawRect(',x,',',y,',',w,',',h,',',cl,');')
circles = doc.getElementsByTagName('circle')
for circle in circles:
cx = roundCoord(circle.attributes['cx'].value)
cy = roundCoord(circle.attributes['cy'].value)
r = roundCoord(circle.attributes['r'].value)
c = circle.attributes['style'].value
if isFilled(c):
cl = getFillColor(c)
print('tft.fillCircle(',cx,',',cy,',',r,',',cl,');')
else:
cl = getStrokeColor(c)
print('tft.drawCircle(',cx,',',cy,',',r,',',cl,');')
doc.unlink()
I prepared also a small demo on Wokwi that contains an example file and explanation how to use it. As the extension ".svg" is not allowed I used ".txt" instead for the vector drawing.
See https://wokwi.com/projects/378850204953865217
The sketch (not very impressive by itself):
/*
Forum: https://forum.arduino.cc/t/creating-graphics-to-display-how-to-get-at-the-colour-codes/1179354
Wokwi: https://wokwi.com/projects/378850204953865217
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(115200);
Serial.println("Start");
tft.begin();
tft.fillScreen(ILI9341_WHITE);
tft.setRotation(1);
drawGraphics();
}
void loop(void) {
}
void drawGraphics() {
// Output of the Python Script to be copied here
tft.fillRect( 20, 20, 100, 100, tft.color565(0x00, 0xFF, 0x00) );
tft.fillRect( 150, 20, 150, 100, tft.color565(0x00, 0x00, 0xFF) );
tft.fillRect( 20, 120, 280, 5, tft.color565(0xD4, 0xAA, 0x00) );
tft.drawRect( 60, 75, 175, 110, tft.color565(0xE1, 0x00, 0x00) );
tft.fillCircle( 140, 190, 40, tft.color565(0xFF, 0x00, 0x00) );
}
Just as a proof of concept, not comprehensive but it is possible to extend the conversion e.g. for line drawings.
Good luck!
P.S.: Just an addition to the Python script. As Adafruit_GFX does not support ellipses but those my be a part of the SVG I added ellipses and substitute them by RoundRect which is not the same but at least shows something "similar" 
Python Script
#!/usr/bin/python3
from xml.dom import minidom
svg_file = 'inkscape2.svg'
doc = minidom.parse(svg_file)
def isFilled(line):
if 'fill:none' in line:
return False
else:
return True
def getFillColor(line):
line = line.upper()
red = '(0x'+line[6:8]
green = ',0x'+line[8:10]
blue = ',0x'+line[10:12]+')'
return 'tft.color565'+red+green+blue
def getStrokeColor(line):
p = line.find('stroke:')+8
line = line.upper()
red = '(0x'+line[p:p+2]
green = ',0x'+line[p+2:p+4]
blue = ',0x'+line[p+4:p+6]+')'
return 'tft.color565'+red+green+blue
def roundCoord(coord):
return round(float(coord))
rects = doc.getElementsByTagName('rect')
for rect in rects:
x = roundCoord(rect.attributes['x'].value)
y = roundCoord(rect.attributes['y'].value)
w = roundCoord(rect.attributes['width'].value)
h = roundCoord(rect.attributes['height'].value)
c = rect.attributes['style'].value
if isFilled(c):
cl = getFillColor(c)
print('tft.fillRect(',x,',',y,',',w,',',h,',',cl,');')
else:
cl = getStrokeColor(c)
print('tft.drawRect(',x,',',y,',',w,',',h,',',cl,');')
circles = doc.getElementsByTagName('circle')
for circle in circles:
cx = roundCoord(circle.attributes['cx'].value)
cy = roundCoord(circle.attributes['cy'].value)
r = roundCoord(circle.attributes['r'].value)
c = circle.attributes['style'].value
if isFilled(c):
cl = getFillColor(c)
print('tft.fillCircle(',cx,',',cy,',',r,',',cl,');')
else:
cl = getStrokeColor(c)
print('tft.drawCircle(',cx,',',cy,',',r,',',cl,');')
ellipses = doc.getElementsByTagName('ellipse')
for ellipse in ellipses:
cx = roundCoord(ellipse.attributes['cx'].value)
cy = roundCoord(ellipse.attributes['cy'].value)
rx = roundCoord(ellipse.attributes['rx'].value)
ry = roundCoord(ellipse.attributes['ry'].value)
c = ellipse.attributes['style'].value
if isFilled(c):
cl = getFillColor(c)
print('tft.fillRoundRect(',cx-rx,',',cy-ry,',',2*rx,',',2*ry,',',abs(rx-ry),',',cl,');')
else:
cl = getStrokeColor(c)
print('tft.drawRoundRect(',cx-rx,',',cy-ry,',',2*rx,',',2*ry,',',abs(rx-ry),',',cl,');')
doc.unlink()