Bitmap to Array for use in graphics.drawImage()

Posted on
  • Hello, I've been looking around for a way to generate an array to store images in for use on an OLED, and while there are lots of results on Google, I don't seem to be able to find anything suitable that works for me.

    I have a monochrome bitmap that I would like to convert to an array that I can put on the Pico. It feels like it should be very simple, but I am not having much luck getting them to work. Any tips/ideas? I am using ImageMagick on os x if anyone has an idea on how to use that to achieve it.

  • Did you see the docs on the Graphics library?

    There's some info at the bottom about getting a bitmap in a form Espruino can use - it should work on OSX, but if it doesn't let me know!

  • The xbm (X bitmap) format might be of use. It's monochrome and is like a declaration in c that you could convert to JavaScript, the output is text:­

    [#define](­ch/?q=%23define) test_width 16
    [#define](­ch/?q=%23define) test_height 7
    static char test_bits[] = {
    0x13, 0x00, 0x15, 0x00, 0x93, 0xcd, 0x55, 0xa5, 0x93, 0xc5, 0x00, 0x80,
    0x00, 0x60 };
  • Actually I'll just have a go bodging up an online converter - give me a few minutes

  • @Gordon Argh! Another case of me not reading things properly, sorry! Yes, there is an example down there of course, AND a link to a base64 encoder. Derp!

    @Wilberforce Thanks for the tip, I'll try that out as I'm getting some noise on my images at the moment.

  • Tadaaa!

    (Not tested, but it sure looks ok)

  • @Gordon Looks good! However, I don't know if it's my setup or something else, but this image:

    Which gave this screenshot when uploaded:

    Makes this on my display:

    What do you think? When I display fonts, etc, it seems to work, and although there is some noise when I base64 encode images they seem to be ok too.

  • Ahh, thanks! I got the bit order wrong - have a go now!

    That'll teach me for not testing it :)

  • Woohoo! Thanks!

  • @Gordon Uh this is really cool! Thanks for it!!!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Bitmap to Array for use in graphics.drawImage()

Posted by Avatar for gomako @gomako