How do I use getDimensions?

Hello,

I am putting a footprint bitmap under my step count.  I am trying to center it, but I can’t draw it width/2 because that is where the image starts and I vary the image based on the watch size (so no hard set).  I was hoping to use getDimensions() under WatchUi>Bitmap to adjust dynamically.  However, I never get the command to show as valid.  It can’t be that hard…What am I missing?

myFeet = WatchUi.loadResource(Rez.Drawables.feet);
 
var _feetSize = myFeet.getDimensions();
I also tried, based on an old post
var _feetSize = myFeet.GetDc();
GetDc didn’t work.
Any thoughts?
Thanks,
Jeff
PS - in the mean time, this works..
var _feetW = myFeet.getWidth(); 
  • WatchUi.loadResource does not return a WatchUi.Bitmap. Instead, it returns either a BitmapResource or a BitmapReference. As you've noticed, these provide getWidth() and getHeight(), but not getDimensions().

    Also, the method getDc() is only available on a BufferedBitmap, which is essentially a blank bitmap you can draw on—not one loaded from resources.

    If you want to work with a Bitmap, you can create one from your resource. A Bitmap allows you to position the image using layout constants like horizontal and vertical centering. This is useful if you're centering the image on a Dc.

    However, if you want to center the bitmap on a different coordinate, you'll still need to manually calculate the offset based on its width and height. Unfortunately, unlike Text, Bitmap does not support justification settings.

    Here is an example for creating and drawing a Bitmap centered on the Dc.

    var bitmap = new Bitmap({
        :rezId => WatchUi.loadResource(rez.Drawables.feet),
        :locX  => WatchUi.LAYOUT_VALIGN_CENTER,
        :locY  => WatchUi.LAYOUT_HALIGN_CENTER
    });
    
    bitmap.draw(dc)
  • If you want to center the bitmap around specific coordinates (centerX and centerY), the code would look like this:

    var bitmap = new Bitmap({
        :rezId => WatchUi.loadResource(rez.Drawables.feet)
    });
    
    bitmap.setLocation(
        centerX - bitmap.getDimensions()[0] / 2,
        centerY - bitmap.getDimensions()[1] / 2
    );
    

    An advantage of using WatchUi.Bitmap over drawing directly with Dc.drawBitmap() is that Bitmap stores its coordinates internally. This allows you to set its position once (e.g., in onLayout()) and then simply call bitmap.draw(dc) in onUpdate() without recalculating the position—assuming the coordinates remain stable.

  • Thanks!

    I didn’t realize the differences between the two bitmap “creations”(var bitmap = .., versus WatychUi.loadResource…).  I thought they were 2 different ways to get to the same point.  Your first solution will probably work best in my case.  it’s a draw once kind of graphic.  Learning was had.  

    Thanks again,

    Jeff

    PS - I was pretty certain about the GetDc(), but I tend towards the throw everything at it after failing for a while.

  • minor edit:  rezId as written wasn’t working.  It needed: 

    :rezId => rez.Drawables.feet,

  • Yes, my bad. :rezId directly takes the ResourceId.