Can you rotate bitmaps?

Can you rotate bitmaps?

Or can you draw images at angles?

Ta ;-)
  • There are nothing automatic in the SDK that can do this. But, it is pretty easy, though costly CPU wise, to transform an image. Not only to rotate, but all the linear transformations (rotate, move, size).
  • One of the watch face examples demonstrates rotations to draw the watch hands.
  • One of the watch face examples demonstrates rotations to draw the watch hands.


    Yep. And it is rather ineffective as it could be done with a single cos/sin - which is the expensive part assuming the CPU of the watches does have a specific instruction :rolleyes:
  • Using an affine transformation matrix does not eliminate the need to use sin/cos, nor does it do anything to reduce the number of times they are called. It is just another way of representing the same calculation.

    As for eliminating sin/cos calls, the example code lifts the expensive calls out of the transformation loop to avoid cost when transforming many points, so that is not a concern.

    That said, you seem to be implying that both sin(x) and cos(x) can be determined accurately and easily given a single call to cos(x) (or sin(x)). This would not be difficult using an offset lookup table, but that doesn't appear to be what you're suggesting.
  • What I'm trying to do is have a triangle or bitmap that spins to indicate heading for a compass
  • Easiest to use draw polygon to draw the triangle pointing the angle necessary.
    The samples have one that draws a rectangle at the correct angle, should be able to change the coords to be a triangle instead.
  • As previously mentioned, the Analog sample has code to rotate a watch hand (which is a rectangle).

    var centerX = dc.getWidth() / 2;
    var centerY = dc.getHeight() / 2;
    var cos = Math.cos(angle);
    var sin = Math.sin(angle);

    // Transform the coordinates
    for (var i = 0; i < 4; i += 1)
    {
    var x = (coords[0] * cos) - (coords[1] * sin);
    var y = (coords[0] * sin) + (coords[1] * cos);
    result= [ centerX+x, centerY+y];
    }

    // Draw the polygon
    dc.fillPolygon(result);
    [/code]
  • Using an affine transformation matrix does not eliminate the need to use sin/cos, nor does it do anything to reduce the number of times they are called. It is just another way of representing the same calculation.


    You right, but you can use the fact that you want to rotate 12 times 2pi/12. So you can make a matrix that will rotate just 2pi/12, and then repeatably apply this to the coordinates. Even with 32-bit precision, you get back to the starting point.

    /Tonny