Importing the librsvg library to load a svg file

R

rrutkowski

Hi!
I need to rasterize a svg file in a .NET project. Currently I'm trying
to use an open source library called librsvg. I've completed all the
dlls and started writing the following wrapper:

[DllImport("librsvg-2-2.dll", SetLastError=true, CharSet =
CharSet.Auto)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name,
int width, int height, out IntPtr error);

public static void LoadSvg(string fileName)
{
IntPtr error;
IntPtr result = rsvg_pixbuf_from_file_at_size(fileName, -1, -1, out
error);
if (error != IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}

However the following call
RsvgWrapper.LoadSvg(@"C:\M_logo.svg");
causes a "The system cannot find the file specified" Win32Exception to
be thrown. The given file exists and is a proper SVG file (the GIMP
loads it fine and it uses the same librsvg library).

Does anyone has an idea, what might be causing the problem?
 
R

rrutkowski

(e-mail address removed) napisal(a):
Hi!
I need to rasterize a svg file in a .NET project. Currently I'm trying
to use an open source library called librsvg. I've completed all the
dlls and started writing the following wrapper:

[DllImport("librsvg-2-2.dll", SetLastError=true, CharSet =
CharSet.Auto)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name,
int width, int height, out IntPtr error);

It seems, that the file_name was marshalled incorectly. I removed the
CharSet property. Now the file is being successfuly open and read
(accordind to File Monitor), but a "Object reference not set to an
instance of an object" exception is thrown at
rsvg_pixbuf_from_file_at_size.

Thanks in advance for any tip
 
C

Chris Dunaway

Hi!
I need to rasterize a svg file in a .NET project. Currently I'm trying
to use an open source library called librsvg. I've completed all the
dlls and started writing the following wrapper:

[DllImport("librsvg-2-2.dll", SetLastError=true, CharSet =
CharSet.Auto)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name,
int width, int height, out IntPtr error);

public static void LoadSvg(string fileName)
{
IntPtr error;
IntPtr result = rsvg_pixbuf_from_file_at_size(fileName, -1, -1, out
error);
if (error != IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}

However the following call
RsvgWrapper.LoadSvg(@"C:\M_logo.svg");
causes a "The system cannot find the file specified" Win32Exception to
be thrown. The given file exists and is a proper SVG file (the GIMP
loads it fine and it uses the same librsvg library).

Does anyone has an idea, what might be causing the problem?

The file not found exception is not referring to the svg file, but
probably to the librsvg or one of its dependents. Make sure that the
library and any other files the library depends on is in a location
where the program can find it. You can try copying the lib and all its
dependents into the programs folder and see if that makes a difference.
 
R

rrutkowski

Chris Dunaway napisal(a):
Hi!
I need to rasterize a svg file in a .NET project. Currently I'm trying
to use an open source library called librsvg. I've completed all the
dlls and started writing the following wrapper:

[DllImport("librsvg-2-2.dll", SetLastError=true, CharSet =
CharSet.Auto)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name,
int width, int height, out IntPtr error);

public static void LoadSvg(string fileName)
{
IntPtr error;
IntPtr result = rsvg_pixbuf_from_file_at_size(fileName, -1, -1, out
error);
if (error != IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}

However the following call
RsvgWrapper.LoadSvg(@"C:\M_logo.svg");
causes a "The system cannot find the file specified" Win32Exception to
be thrown. The given file exists and is a proper SVG file (the GIMP
loads it fine and it uses the same librsvg library).

Does anyone has an idea, what might be causing the problem?

The file not found exception is not referring to the svg file, but
probably to the librsvg or one of its dependents. Make sure that the
library and any other files the library depends on is in a location
where the program can find it. You can try copying the lib and all its
dependents into the programs folder and see if that makes a difference.

The library seems to load fine. I checked the dependencies in
Dependency Walker. The "file not found" exception was a Win32Exception
thrown by me. It was caused by incorrectly marshalled file name string.
 
R

rrutkowski

(e-mail address removed) napisal(a):
(e-mail address removed) napisal(a):
Hi!
I need to rasterize a svg file in a .NET project. Currently I'm trying
to use an open source library called librsvg. I've completed all the
dlls and started writing the following wrapper:

[DllImport("librsvg-2-2.dll", SetLastError=true, CharSet =
CharSet.Auto)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name,
int width, int height, out IntPtr error);

It seems, that the file_name was marshalled incorectly. I removed the
CharSet property. Now the file is being successfuly open and read
(accordind to File Monitor), but a "Object reference not set to an
instance of an object" exception is thrown at
rsvg_pixbuf_from_file_at_size.

Solved. The solution is to call the g_init_type() function from the
libgobject library before calling the rsvg_pixbuf_from_file_at_size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top