Type Function Return value DisplayObject Revision Release 2022.3683 Keywords SVG, nanosvg, newImage See also nanosvg.newTexture() nanosvg.*
Displays an image on the screen containing the rendered SVG.
nanosvg.newImage( 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. The x coordinate of the image on screen.
Number. The y coordinate of the image on screen.
Number. The content width of the image, which is the width within the reference screen of the content.
Number. The content height of the image, which is the height within the reference screen of the content.
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 testSvg = nanosvg.newImage( { filename = "test.svg", x = display.contentCenterX, y = display.contentCenterY, width = 100, height = 100 })
local nanosvg = require( "plugin.nanosvg" ) local circle = nanosvg.newImage( { data = "<svg viewBox='0 0 200 200'><circle cx='100' cy='100' r='100'/></svg>", x = display.contentCenterX, y = display.contentCenterY, width = 100, height = 100 })