I wanted to understand the technique used by the image2cpp program to encode images. So I uploaded an image, grabbed the generated output, and set about rendering it on Khan Academy. It took a while to understand, and at some point I had to look through the source code, but I finally got it to display.
Turns out the hexadecimal values in the output do not correspond to hexadecimal-style color codes (such as
0xffffff for white or
0x00ff00 for green). Instead the trick is to convert them into binary numbers. For example
0xf7 becomes binary
11110111. A one corresponds to a white pixel, and a zero to a black pixel, such that eight pixels are encoded by each hexcode.
- Created on April 2016