Forums > Dev

Help with SVG image

September 27, 2009 | 2:41 am

Hi there,

I need to have a big SVG image available in my external. The idea is to make my UI object box act as a window into my image showing certain portions of it. I don’t want to give the user the option of loading the image, because it’s an intrinsic part of my object and it is never gonna change. So ideally I would like the image data to exist as soon as the external is instantiated and be readily accessible.

I see there’s a function in the JGraphics API that could help me achieve this:

t_jsurface* jgraphics_image_surface_create_from_resource(const void* moduleRef, const char *resname);

In the comments of the function it says that to main{} will be passed a pointer to the external’s module.
However I thought main could only take 2 arguments (int argc, char *argv) or 0 arguments (void)

Can someone shed some light on this and explain how to set up my Xcode project appropriately?

Thank you much.

- Luigi

September 28, 2009 | 2:21 pm

Hi Luigi,

You are correct about the convention for 0 or 2 arguments to main() — which means that with 1 argument you will get a compiler warning. Sorry. We did it with one argument anyway.

The following example comes from the matrixctrl object. It is using PNG rather than SVG — I’m not sure if this mechanism supports SVG files directly…

int main(void *moduleRef)
	t_class *c;


	s_matrixctrl_cell = jgraphics_image_surface_create_from_resource(moduleRef, "matrixctrl_cell");
	s_matrixctrl_bkgnd = jgraphics_image_surface_create_from_resource(moduleRef, "matrixctrl_bkgnd");

	return 0;

You can look inside of the matrixctrl.mxo bundle to see that the png files are in there are resources.


September 28, 2009 | 11:47 pm

Ok, I’ll try that.

Thanks Tim.

- Luigi

April 20, 2011 | 1:30 am

One more thing about this…

I just realized that there is memory allocated to s_matrixctrl_cell and s_matrixctrl_bkgnd, but then… don’t I need to manage the memory associated with each t_jsurface ?

- Luigi

April 21, 2011 | 9:43 pm

You don’t need to free it, because jgraphics_image_surface_create_from_resource() allocate the memory in the main function for every instance of the class. Since the class never needs to be gone, in order to create new instances, you don’t need to free the memory.

Viewing 5 posts - 1 through 5 (of 5 total)