[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage problem

From: Ivan Vučica
Subject: Re: NSImage problem
Date: Fri, 16 Mar 2012 16:13:04 +0100

Loading of the image has failed for some reason.

If you are correctly mentioning the file name in "GNUmakefile" as a resource (and hence it gets copied inside the .app), try instantiating the image using method +[NSImage imageNamed:].

This should work:
NSImage *myImage = [NSImage imageNamed:@"imagen"]; // autoreleased

Optionally retain it; the object returned is autoreleased.

Alternatively get the path like this:
NSString *path = [[NSBundle mainBundle] pathForResource:@"imagen" ofType:@"png"];
NSImage *myImage = [[NSImage alloc] initWithContentsOfFile:path]; // retained already

It's a bad idea to reference to things using an absolute path. Always try to refer to paths using some API, even when referring to paths inside the app bundle. When you move the app to a new platform, you'll be glad you did.

If nothing of the above helps, try using a different .png to verify your GNUstep installation is capable of decoding the PNG file format.

On Thu, Mar 15, 2012 at 23:58, gusborsa <> wrote:

Hello, I´m trying to create a NSImage object from a png type image. My code:

NSImage *myImage = [[NSImage alloc] initWithContentsOfFile:

but this method returns "nil", the description message from the myImage
object returns (NULL).

I Verified the path with the fileExistsAtPath (NSFileManager) method and
it's OK. I'm working on WinXP.

View this message in context:
Sent from the GNUstep - Help mailing list archive at

Help-gnustep mailing list

Ivan Vučica -

reply via email to

[Prev in Thread] Current Thread [Next in Thread]