how to get the real (unscaled) size of an embedded image in the svg document?!

前端 未结 2 917
小鲜肉
小鲜肉 2020-12-20 15:11

I have a SVG document with the image entry in it:

          


        
2条回答
  •  梦毁少年i
    2020-12-20 15:34

    I did a little research and was unable to discover a property that you could enumerate to get the images actual width and height. However there was another approach which seemed interesting which included an xmlHttpRequest to get the image and enumerate it's dimensions.

    That made me think of a slightly faster way. The solution is to utilize a hidden

    as a working container and pulling down the necessary images (using ) where you can enumerate width and height there. This pseudoCode For example:

    • Iterate through collection of images
    • Create an image node with the appropriate src path
    • Append the new node to div#ImageEnumeration
    • Enumerate image retrieved

    Just for grins (if it helps) here was a draft of some code for the xmlHttpRequest:

    var imgRequest = 
      function(sImgUrl, oRequestCallback){
        var xhr = new XMLHttpRequest();  
        xhr.open('GET', sImgUrl, true);  
        xhr.onreadystatechange = oRequestCallback;
        xhr.send(null);  
        };
    
    var xhrImageRequest =
      function(result){
        var oImageDimensions;
        //Create and append  to 
    //Get image width and height //return image width and height }; var myImage = imgRequest("http://example.com/myImage.png", xhrImageRequest);

    If this doesn't solve your problem, I hope it will at least create some new ideas in solving it.

提交回复
热议问题