help-gnustep
[Top][All Lists]
Advanced

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

Re: NSImage problem


From: Ivan Vučica
Subject: Re: NSImage problem
Date: Thu, 29 Mar 2012 15:28:47 +0200

Hi,

If that's the case, I'll repeat and expand upon what Fred said: the cause might be that your version of gnustep-gui was built without PNG support.

Please follow Fred's instruction of listing the contents of the array containing supported data types.

This should work:
NSLog(@"%@", [NSImage imageUnfilteredFileTypes]);

If it doesn't print out an array (I'm not sure if GNUstep does), try this:
for(NSString * type in [NSImage imageUnfilteredFileTypes])
  NSLog(@"- %@", type);

or if your compiler doesn't support "fast enumeration", try this:
NSEnumerator *e = [[NSImage imageUnfilteredFileTypes] objectEnumerator];
for(NSString * type = [e nextObject]; type; type = [e nextObject])
  NSLog(@"- %@", type);

If you don't see png listed in the output, NSImage cannot load a png under your installation.

On Wed, Mar 28, 2012 at 23:09, gusborsa <gusborsa@yahoo.com.mx> wrote:

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 <gusborsa@yahoo.com.mx> 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
>> Help-gnustep@gnu.org
>> https://lists.gnu.org/mailman/listinfo/help-gnustep
>>
>
>
>
> --
> Ivan Vučica - ivan@vucica.net
>
> _______________________________________________
> Help-gnustep mailing list
> Help-gnustep@gnu.org
> 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
Help-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/help-gnustep



--
Ivan Vučica - ivan@vucica.net



reply via email to

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