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 <[email protected]> wrote:

>
> Hello, I´m trying to create a NSImage object from a png type image. My
> code:
>
> NSImage *myImage = [[NSImage alloc] initWithContentsOfFile:
> @"c:/MiProyect/Resources/imagen.png"];
>
> 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.
>
> Thanks
> --
> View this message in context:
> http://old.nabble.com/NSImage-problem-tp33513960p33513960.html
> Sent from the GNUstep - Help mailing list archive at Nabble.com.
>
>
> _______________________________________________
> Help-gnustep mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/help-gnustep
>



-- 
Ivan Vučica - [email protected]
_______________________________________________
Help-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-gnustep

Reply via email to