Skip to content

Instantly share code, notes, and snippets.

@falkolab
Created October 29, 2015 11:45
Show Gist options
  • Save falkolab/e59e9aad16a7e681c659 to your computer and use it in GitHub Desktop.
Save falkolab/e59e9aad16a7e681c659 to your computer and use it in GitHub Desktop.
How to use SVG as View backgroundImage
$.getView().backgroundImage = getImageFileFromSVG({
image : "/images/hearts.svg",
width : 400,
height : 400,
top : 0,
left : 0
});
function getImageFileFromSVG(svgOpts) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory,
Ti.Utils.md5HexDigest(JSON.stringify(svgOpts)));
if (!file.exists()) {
var SVG = require('com.geraudbourdin.svgview');
if (!file.write(SVG.createView(svgOpts).toImage())) {
Ti.API.error("Can't to save file");
return null;
}
}
return file.exists() ? file.getNativePath(): null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment