Loads an SVG document from an SVG file from memory.
#include "l_bitmap.h"
L_LTSVG_API L_INT L_SvgLoadDocumentMemory(buffer, bufferSize, docHandle, options)
Pointer to the file in memory to be loaded.
Size of the file in memory (in bytes).
Pointer to the L_SvgNodeHandle referencing the target SVG document.
Optional pointer to a structure containing SVG load options. Pass NULL to use the default options.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Support for SVG is available in Document and Medical Imaging toolkits.
To get and set information on the document bounds and resolution refer to SVG Size, Bounds and Flat.
When the SVG document data is no longer needed, you must call L_SvgFreeNode to free storage allocated for the SVG document.
Win32, x64, Linux.
This example will save an SVG document to a memory buffer and reload it.
L_INT SvgLoadDocumentMemoryExample(L_VOID)
{
L_INT nRet = SUCCESS;
L_TCHAR srcFileName[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("Leadtools.doc"));
L_TCHAR dstFileName[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("Output.svg"));
L_TCHAR msg[1024] = {0};
// Load as SVG from source document
wsprintf(msg, L_TEXT("Loading: %s\n"), srcFileName);
wprintf(msg);
LOADSVGOPTIONS svgOptions = {0};
svgOptions.uStructSize = sizeof(LOADSVGOPTIONS);
nRet = L_LoadSvg(srcFileName, &svgOptions, NULL);
if(nRet != SUCCESS)
return nRet;
// Save it to memory as SVG
wsprintf(msg, L_TEXT("Saving to memory\n"));
wprintf(msg);
L_UCHAR* buffer = NULL;
L_UINT bufferSize = 0;
nRet = L_SvgSaveDocumentMemory(svgOptions.SvgHandle, &buffer, &bufferSize, NULL);
// Free the source SVG document
L_SvgFreeNode(svgOptions.SvgHandle);
svgOptions.SvgHandle = NULL;
if(nRet == SUCCESS)
{
// Load from memory
wsprintf(msg, L_TEXT("Loading from memory\n"));
wprintf(msg);
L_SvgNodeHandle docHandle = NULL;
nRet = L_SvgLoadDocumentMemory(buffer, bufferSize, &docHandle, NULL);
// Free the memory allocated by L_SvgSaveDocumentMemory
L_SvgFreeMemory(buffer);
if(nRet == SUCCESS)
{
// Save it to file on disk as SVG
wsprintf(msg, L_TEXT("Saving: %s\n"), dstFileName);
wprintf(msg);
nRet = L_SvgSaveDocument(dstFileName, docHandle, NULL);
}
// Free the SVG document
L_SvgFreeNode(docHandle);
}
return nRet;
}