By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 2,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

Importing the librsvg library to load a svg file

P: n/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?

Sep 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

rrutkow...@gmail.com 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

--
Rudy

Sep 28 '06 #2

P: n/a
rr********@gmail.com wrote:
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.

Sep 28 '06 #3

P: n/a

Chris Dunaway napisal(a):
rr********@gmail.com wrote:
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.

--
Rudy

Sep 29 '06 #4

P: n/a

rr********@gmail.com napisal(a):
rrutkow...@gmail.com 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.

--
Rudy

Sep 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.