Created
October 29, 2015 11:45
-
-
Save falkolab/e59e9aad16a7e681c659 to your computer and use it in GitHub Desktop.
How to use SVG as View backgroundImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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