Type Function Return value TextureResourceExternal Revision Release 2024.3703 Keywords SVG, nanosvg, newTexture See also nanosvg.newImage() nanosvg.*
Creates a texture instance (TextureResourceExternal) containing the rasterized SVG.
Created textures are subject to manual texture memory management. See the Texture Loading/Management guide for more information.
nanosvg.newTexture( params )
Table. Table containing the required parameters for the new object — see the next section for details.
At least one data source — filename
, filePath
, data
—
String. Indicates the name of the SVG file to load, relative to baseDir
.
Constant. Specifies the base directory where filename
is located. Options include system.ResourceDirectory
, system.DocumentsDirectory
, system.ApplicationSupportDirectory
, system.TemporaryDirectory
and system.CachesDirectory
. Default is system.ResourceDirectory
.
String. Indicates the full file path of the SVG file to load.
String. Contains XML data of the SVG to be rasterized.
Number. Specifies the horizontal pixel dimensions of the texture that the SVG is rendered to. If this is omitted, the texture width will be deduced from the SVG width/height ratio.
Number. Specifies the vertical pixel dimensions of the texture that the SVG is rendered to. If this is omitted, the texture height will be deduced from the SVG width/height ratio.
String. Specifies how the rasterized SVG should fit into the texture. This only applies if both pixelWidth
and pixelHeight
are specified. Options include:
"letterbox"
— This option (default) fits the entire rasterized SVG into the texture width/height, leaving letterbox regions transparent."zoomEven"
— This option fills the texture width/height with the rasterized SVG so that its smaller dimension fits into the texture.Number. Specifies how a scaled rasterized SVG will be positioned within the texture width/height. A value of 0.5
(default) will position it in the middle of the texture; 0
to the top or left; 1
to the bottom or right.
Number. Number for transforming between different SVG units (pixels, points, 96
.
local nanosvg = require( "plugin.nanosvg" ) local tex = nanosvg.newTexture( { filename = "test.svg", }) if tex then local testSvg = display.newImage( tex.filename, tex.baseDir, display.contentCenterX, display.contentCenterY ) tex:releaseSelf() else print( "Error rendering SVG" ) end