Inverse of Graphics.asUrl

Posted on
  • Hi Gordon,

    Is there an inverse equivalent of­phics_asURL ? I.e if I've got a base64 encoded image, can I convert it to something I can pass to Graphics to display on the screen?

  • It depends on what exactly the image was encoded as... If it's a base64 image of raw bits then you can just shove it in an object with width, height and buffer fields like does (­bitmaps)

    However if it's a windows bitmap file (which is what asURL does) then you can convert it to a binary form with atob(...) and then feed that into the bitmap loader module which will give you an image which you can draw with graphics as well:

    If a normal PC application is encoding an image to a URL it may well end up encoding it as a PNG of JPEG image - and I'm afraid there aren't any decoders for those in Espruino though.

  • Ah, perfect. I just need to read your docs better. I was stuck on­cs looking through all the functions and didn't see the link to which would have lead me to

  • Great! If you think of any search keywords that might have helped you find those pages better, please can you let me know?

    If you click the This page is auto-generated from GitHub link at the bottom of the screen you should go to the page's source on GitHub where it's got a * KEYWORDS: ... list. If there's anything missing it's trivial for me to add, and it might help someone else out in the future.

  • I have played with the idea of having an easy way to debug graphics locally and made the following module­94a3e2d7cf122c6013e8935cf

    It wraps the Graphics.createArrayBuffer by calling require('./webGraphics').add(Graphics) and exposes http://localhost:8000 endpoint with canvas renderer for Espruino.

  • Nice! There's g.dump() which gets picked up and displayed in the Web IDE:

    But that doesn't update in real-time like yours. Actually with a little bit of abstraction around button handling you could make it so you could remotely view and also control a device. It'd be a really neat way of quickly making a web interface for a device.

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

Inverse of Graphics.asUrl

Posted by Avatar for dave_irvine @dave_irvine