Thank you Ivan, I was following yours advices: 1) I made sure that the image was in the app's resources directory (through the Gnumakefile). 2) The NSBundle is a very nice class, but the results were the same, the NSImage pointer returned by the alloc method was NULL. 3) the same result instansiating the image using imageNamed.
I appreciate your help. Ivan Vučica wrote: > > 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 > > -- View this message in context: http://old.nabble.com/NSImage-problem-tp33513960p33544855.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
