How do I get dimensions of an image SAPUI5?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have an image which is being set through:



var oImage = new sap.m.Image({
id: image0,
src: "img/image0.jpg"
});


I want to figure out the width and height of the image ?



I have tried oImage.getWidth() and oImage.getHeight() but those return empty. I have also tried parseInt(oImage.getWidth()) and parseInt(oImage.getHeight()) but those return NaN.










share|improve this question

























  • Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

    – Ivan Kaloyanov
    Jan 3 at 7:50











  • what do you mean that image is init correctly?

    – Umar Abdullah
    Jan 3 at 8:02











  • would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

    – Ivan Kaloyanov
    Jan 3 at 8:07











  • I would like to know how to get the dimension of image.What steps / code i have to use.

    – Umar Abdullah
    Jan 3 at 8:10











  • Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

    – Ivan Kaloyanov
    Jan 3 at 8:16




















0















I have an image which is being set through:



var oImage = new sap.m.Image({
id: image0,
src: "img/image0.jpg"
});


I want to figure out the width and height of the image ?



I have tried oImage.getWidth() and oImage.getHeight() but those return empty. I have also tried parseInt(oImage.getWidth()) and parseInt(oImage.getHeight()) but those return NaN.










share|improve this question

























  • Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

    – Ivan Kaloyanov
    Jan 3 at 7:50











  • what do you mean that image is init correctly?

    – Umar Abdullah
    Jan 3 at 8:02











  • would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

    – Ivan Kaloyanov
    Jan 3 at 8:07











  • I would like to know how to get the dimension of image.What steps / code i have to use.

    – Umar Abdullah
    Jan 3 at 8:10











  • Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

    – Ivan Kaloyanov
    Jan 3 at 8:16
















0












0








0








I have an image which is being set through:



var oImage = new sap.m.Image({
id: image0,
src: "img/image0.jpg"
});


I want to figure out the width and height of the image ?



I have tried oImage.getWidth() and oImage.getHeight() but those return empty. I have also tried parseInt(oImage.getWidth()) and parseInt(oImage.getHeight()) but those return NaN.










share|improve this question
















I have an image which is being set through:



var oImage = new sap.m.Image({
id: image0,
src: "img/image0.jpg"
});


I want to figure out the width and height of the image ?



I have tried oImage.getWidth() and oImage.getHeight() but those return empty. I have also tried parseInt(oImage.getWidth()) and parseInt(oImage.getHeight()) but those return NaN.







sapui5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 8:01







Umar Abdullah

















asked Jan 3 at 5:55









Umar AbdullahUmar Abdullah

717419




717419













  • Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

    – Ivan Kaloyanov
    Jan 3 at 7:50











  • what do you mean that image is init correctly?

    – Umar Abdullah
    Jan 3 at 8:02











  • would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

    – Ivan Kaloyanov
    Jan 3 at 8:07











  • I would like to know how to get the dimension of image.What steps / code i have to use.

    – Umar Abdullah
    Jan 3 at 8:10











  • Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

    – Ivan Kaloyanov
    Jan 3 at 8:16





















  • Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

    – Ivan Kaloyanov
    Jan 3 at 7:50











  • what do you mean that image is init correctly?

    – Umar Abdullah
    Jan 3 at 8:02











  • would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

    – Ivan Kaloyanov
    Jan 3 at 8:07











  • I would like to know how to get the dimension of image.What steps / code i have to use.

    – Umar Abdullah
    Jan 3 at 8:10











  • Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

    – Ivan Kaloyanov
    Jan 3 at 8:16



















Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

– Ivan Kaloyanov
Jan 3 at 7:50





Make sure the image is init correctly. Then your oImage.getWidth() and oImage.getHeight() will work :)

– Ivan Kaloyanov
Jan 3 at 7:50













what do you mean that image is init correctly?

– Umar Abdullah
Jan 3 at 8:02





what do you mean that image is init correctly?

– Umar Abdullah
Jan 3 at 8:02













would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

– Ivan Kaloyanov
Jan 3 at 8:07





would you attack screenshot of your oImage object or atleast the output of console.log(oImage);

– Ivan Kaloyanov
Jan 3 at 8:07













I would like to know how to get the dimension of image.What steps / code i have to use.

– Umar Abdullah
Jan 3 at 8:10





I would like to know how to get the dimension of image.What steps / code i have to use.

– Umar Abdullah
Jan 3 at 8:10













Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

– Ivan Kaloyanov
Jan 3 at 8:16







Like I said oImage.getWidth() and oImage.getHeight() works as long as your object is sap.m.Image. openui5.hana.ondemand.com/#/api/sap.m.Image

– Ivan Kaloyanov
Jan 3 at 8:16














2 Answers
2






active

oldest

votes


















0














The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.






var oImage = new sap.m.Image("image0", {
src: "img/load.gif",
height: "30vh",
width: "30vw"
});





This oImage.getWidth() will return "30vw"






share|improve this answer

































    0














    Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:



    var image = this.byId("image0"); 
    var oDomRef = image.getDomRef()
    console.log(oDomRef .width, oDomRef .height);


    It will give the image width and height in px.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017019%2fhow-do-i-get-dimensions-of-an-image-sapui5%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.






      var oImage = new sap.m.Image("image0", {
      src: "img/load.gif",
      height: "30vh",
      width: "30vw"
      });





      This oImage.getWidth() will return "30vw"






      share|improve this answer






























        0














        The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.






        var oImage = new sap.m.Image("image0", {
        src: "img/load.gif",
        height: "30vh",
        width: "30vw"
        });





        This oImage.getWidth() will return "30vw"






        share|improve this answer




























          0












          0








          0







          The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.






          var oImage = new sap.m.Image("image0", {
          src: "img/load.gif",
          height: "30vh",
          width: "30vw"
          });





          This oImage.getWidth() will return "30vw"






          share|improve this answer















          The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.






          var oImage = new sap.m.Image("image0", {
          src: "img/load.gif",
          height: "30vh",
          width: "30vw"
          });





          This oImage.getWidth() will return "30vw"






          var oImage = new sap.m.Image("image0", {
          src: "img/load.gif",
          height: "30vh",
          width: "30vw"
          });





          var oImage = new sap.m.Image("image0", {
          src: "img/load.gif",
          height: "30vh",
          width: "30vw"
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 4 at 8:22

























          answered Jan 4 at 8:13









          O.OO.O

          827422




          827422

























              0














              Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:



              var image = this.byId("image0"); 
              var oDomRef = image.getDomRef()
              console.log(oDomRef .width, oDomRef .height);


              It will give the image width and height in px.






              share|improve this answer




























                0














                Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:



                var image = this.byId("image0"); 
                var oDomRef = image.getDomRef()
                console.log(oDomRef .width, oDomRef .height);


                It will give the image width and height in px.






                share|improve this answer


























                  0












                  0








                  0







                  Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:



                  var image = this.byId("image0"); 
                  var oDomRef = image.getDomRef()
                  console.log(oDomRef .width, oDomRef .height);


                  It will give the image width and height in px.






                  share|improve this answer













                  Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:



                  var image = this.byId("image0"); 
                  var oDomRef = image.getDomRef()
                  console.log(oDomRef .width, oDomRef .height);


                  It will give the image width and height in px.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 4 at 9:01









                  Rahul BhardwajRahul Bhardwaj

                  1,8331918




                  1,8331918






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017019%2fhow-do-i-get-dimensions-of-an-image-sapui5%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules