trying to insert image as bitmap to the watch face without any success

Hi, I'm using again the forum in order to get a solution to my problem.

I am trying to insert an image as a bitmap via source to the watch face. I have added a line in watchimageView.mc : 

dc.drawBitmap(dc.getWidth()/2, dc.getHeight()/2, "naruto icon for watch face.bmp")

it says "Aborting launch due to failed build" but I did not understand how to fix the mismatched inputs the console means.

I am adding the watch face file hopefully you will manage to help me again.

TY a lot and sorry if I am asking a lot of question in this forum.

https://drive.google.com/drive/folders/1dFCovr8DdzEDkUCMs-Fnll90HZlX6O6_?usp=sharing

  • You need to load the resource like this:

    wp = Ui.loadResource(Rez.Drawables.id_pic);

    where in resources, you have something like this:

     <bitmap id="id_pic" filename="pic.png" />

    and then to display it something like this:

    dc.drawBitmap(bmX, 29, wp);

    If you use the widget template for a new project, you can also see how this can be done using a layout - the pipe smoking monkey.

  • Hi, ty for your answer. I tried my best following what you wrote and got the following errors:    https://ibb.co/ZVR7j02

    I'm adding images of my watchfaceView.mc  ,   navigator  and of the drawables.xml 

    can you check what have I done wrong with the explanation and what I need to do to solve it?

    watchfaceView.mc: https://ibb.co/280vq5d

    navigator: https://ibb.co/DgWHSYk

    drawables.xml : https://ibb.co/ngzmGvj

  • declare wp as a vairable in your class.

    var wp;

    And you must set a value for bmX.

    var bmX=20;

    for example.

  • followed it and I got those errors: https://ibb.co/Vg6DTnx
    I am adding an image of the changes I made just to make sure I did those right either: https://ibb.co/6Xvtcnc

    TY again Jim for the help!

  • Post the error you get directly here You don't need to link stuff.  You can just use insert>code.

    Here's the very basics.  Load the bitmap in initialize(), and then draw it in onUpdate().

    class myView extends WatchUi.Watchface {
        var myBmp;
        
        function initialize() {
            WatchFace.initialize();
            myBmp=WatchUi.loadResource(Rez.Drawables.id_pic);  //load the bitmap using your id in place of id_pic
        }
        
        function onUpdate(dc) {
            var x=10,y=10;      //upper left is at 10,10
            ...
            dc.drawBitmap(x, y, myBmp);
            ...
        }
    }

  • I don't know why it is like that but Ive tried the solution and got the following error in myBmp=Ui.loadResource line : watchimageView.mc:11: Undefined symbol "Ui" detected. even tough it wasn't before. can you help me again? sorry for the questions that keep coming from my side.

    Im adding the watchimageView.mc as text because it doesn't let me add it as a code:

    import Toybox.Graphics;
    import Toybox.Lang;
    import Toybox.System;
    import Toybox.WatchUi;

    class watchimageView extends WatchUi.WatchFace {
    var myBmp;

    function initialize() {
    WatchFace.initialize();
    myBmp=Ui.loadResource(Rez.Drawables.naruto); //load the bitmap using your id in place of id_pic
    }

    function onUpdate(dc) {
    var x=10,y=10; //upper left is at 10,10
    dc.drawBitmap(x, y, myBmp);
    }
    }


    // Load your resources here
    function onLayout(dc as Dc) as Void {
    setLayout(Rez.Layouts.WatchFace(dc));
    }

    // Called when this View is brought to the foreground. Restore
    // the state of this View and prepare it to be shown. This includes
    // loading resources into memory.
    function onShow() as Void {
    }

    // Update the view
    function onUpdate(dc as Dc) as Void {
    // Get and show the current time
    var clockTime = System.getClockTime();
    var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%02d")]);
    var view = View.findDrawableById("TimeLabel") as Text;
    view.setText(timeString);

    // Call the parent onUpdate function to redraw the layout
    View.onUpdate(dc);
    }

    // Called when this View is removed from the screen. Save the
    // state of this View here. This includes freeing resources from
    // memory.
    function onHide() as Void {
    }

    // The user has just looked at their watch. Timers and animations may be started here.
    function onExitSleep() as Void {
    }

    // Terminate any active timers and prepare for slow updates.
    function onEnterSleep() as Void {
    }

  • Use WatchUi instead of just Ui.

    I correct the code I posted.  I'm just used to having

    using Toybox.WatchUi as Ui;

    in my code.

  • whoops, thought it might be the reason but i used w instead of capital W so it didn't solve it when i tried. TY a lot, it is working now. really appreciate it!

  • My own rule of thumb is to test on a real device at least as long as it took to develop an app before putting it in the store.

  • Hello Kfri would you mind posting the whole project as I am also encountering some trouble