• I want to draw bitmap (buffer) data directly with inlineC and noticed that the method Graphics.drawImage() used the setPixel(...) to draw the bitmap (buffer) data at last in jswrap_graphics.c, but the method Graphics.drawString() is called graphicsFillRect() and graphicsFillRectDevice to draw and returned return gfx->fillRect(gfx, (int)x1, (int)y1, (int)x2, (int)y2, col), Why this way? What's the difference between the two and which one is more efficient to draw bitmap data?

  • drawString uses graphicsFillRect because bitmap fonts can be 'scaled' - you can have a bitmap font scaled up by 4x in which case each 'pixel' is a 4x4 rect.

    For drawing pixel by pixel, setPixel is the way to go.

    However what device are you using InlineC on? For instance on Bangle.js it can make a lot of sense to have an offscreen buffer and to use Inline C to write direct into that buffer, and then use g.drawImage to draw that to the screen (drawImage has a special fast path for blits)

    There's an example of that at https://github.com/espruino/BangleApps/bĀ­lob/master/apps/geissclk/clock.js

  • Great!! @Gordon You just like a beacon in my mist! :)
    I'm going to try

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

What's the difference between drawImage and drawString to draw pixels

Posted by Avatar for tyronehell @tyronehell