Correct way to load images

Posted on
  • Hello! This is my first time writing on the forum.
    I got my Banglejs2 last week and having plenty of fun with it.

    I have modified a clockface and was wondering if the way I load images is correct, the original code uses this

    function getImage() {
      return require("heatshrink").decompress(atob("..."));
    }
    
    function draw() {
      g.drawImage(getImage());
    }
    

    While it works flawlessly, I was wondering if this is the correct way, I guess that if the draw is called once per minute it loads the image again every time, would this impact battery life?
    I guess, on the bright side that it does not keep the loaded image into RAM after drawing it on the screen which may be good for a limited memory device.

    Should I make the code keep the image in memory and load it once at the start?
    Would having to draw the image multiple times in different parts of the screen change anything?

    Thank you very much for your help :)

  • Once per minute it probably doesn't matter much, once per second may matter a bit more but still not critical. See also this https://forum.espruino.com/conversations/376504/#16554635 in that case decompressing image took extra 15ms of cpu time. CPU draws about 4mA when running so 15ms of 4mA is not that much of power. See also power draw of other components for comparison https://www.espruino.com/Bangle.js2#power-consumption

  • Thank you @fanoush for the links, I won’t bother too much changing it then

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

Correct way to load images

Posted by Avatar for JunkyByte @JunkyByte

Actions