Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Scaling SVG

Hi,
I'm trying to to scale a vector graphic in SVG format and display it in a table row. I can scale the SVG by using a WebView, but fail to display it properly. Here's what I do:

// create row...
var row = Ti.UI.createTableViewRow();
row.height = 75;

// scale SVG using WebView... works...
var scale = Ti.UI.create2DMatrix().scale(0.2);
var p = Ti.UI.createWebView({ url:'./images/test.svg', size:{ width:50, height:50 }, transform:scale });

// doesn't display anything where the image should appear in the row...
var photo = Ti.UI.createImageView({
                image:p.toImage(),
                top:5, left:10
});
row.add(photo);

You might say I can drop the call to createImageView entirely, and instead add top and left to the WebView, but then the image does appear close to the center of the corresponding row, not on the left. Here's what I mean:

// same as above...
var p = Ti.UI.createWebView({ url:'./images/test.svg', size:{ width:50, height:50 }, transform:scale, top:5, left:10});
row.add(p);

Any help appreciated.
-tom

— asked July 24th 2010 by tom quas
  • iphone
  • mobile
  • svg
2 Comments
  • hello,

    i know this question was asked a year ago but i was wondering how you even got the webview to load up your svg file. i am really new to coding in general so i'm not sure if its something wrong with my code or with android. my webview code follows yours TO THE LETTER yet when i try and view it it keeps saying "the web page at file:////android_asset/resources/file.svg could not be loaded as :the requested file was not found." i have the svg saved in my resources folder. is that the wrong place?

    — commented January 6th 2012 by Anthony Puah
  • ive heard that android doesnt support svg but i'm not sure. was your app for android or iOS?

    — commented January 6th 2012 by Anthony Puah

1 Answer

  • The Webview takes some time to load the HTML.
    Adding a timeout before calling toImage solved it (~10000 ms)..

    — answered September 24th 2015 by David Cruz Jimenez
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.