Render a section of a bitmap

Hi folks,

Just asking to see if the SDK supports the ability to render a partial section of a bitmap, like so;



I'm interested in displaying many different images tiled from a single bitmap file, similar to a sprite sheet.
Couldn't find anything in the documentation so far.

Cheers.
  • No, you cannot really do exactly what you want given what is available in the ConnectIQ 2.2.2 SDK.

    That said, the font system does exactly what you describe, but there are limitations. The first is that it only allows two colors (foreground and background). You could probably work around that by having multiple glyphs that contain the image data for pixels of various colors, or you might be able to do something by having multiple fonts and overlaying them. The other limitation is that you have to be able to refer to each sprite via a character.

    I'm not sure how well it would work, but you could try it.

    Are you making a game?

    Travis
  • Hi,
    as Travis already mentioned, the current SDK does not exactly support what you are looking for.

    But in addition to the workarounds described by Travis, there might be another workaround that could help.

    Instead of having the bitmap placed at a fixed point, you could also move the bitmap around.
    You can use negative coordinates.

    For example:

    dc.drawBitmap(0, 0, bitmap) will place the bitmap at the upper left corner.
    dc.drawBitmap(-x1, -y1, bitmap); would shift the same bitmap x1 points to the left and y1 points up.
    dc.drawBitmap(x1, y1, bitmap); would shift the bitmap x1 points to the right and y1 points down.

    With that you could show different sections of the bitmap on the screen.
  • That said, the font system does exactly what you describe, but there are limitations. The first is that it only allows two colors (foreground and background). You could probably work around that by having multiple glyphs that contain the image data for pixels of various colors, or you might be able to do something by having multiple fonts and overlaying them. The other limitation is that you have to be able to refer to each sprite via a character.


    Thanks Travis - this is exactly my next strategy.

    I wanted to avoid this approach for a few reasons. Firstly, multiple colours per glyph requires multiple writes to the same (x,y) position. Secondly, additional colours requires extra individual glyph resources. Lastly, positioning is painful, unless each glyph is a fixed height and width.
  • I wanted to avoid this approach for a few reasons. Firstly, multiple colours per glyph requires multiple writes to the same (x,y) position. Secondly, additional colours requires extra individual glyph resources. Lastly, positioning is painful, unless each glyph is a fixed height and width.

    Also, I've used this technique to render nicely anti-aliased text from a custom font :)