Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: NSImage problem

19 views
Skip to first unread message

gusborsa

unread,
Mar 28, 2012, 5:09:25 PM3/28/12
to Help-g...@gnu.org

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 <gusb...@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-g...@gnu.org
>> https://lists.gnu.org/mailman/listinfo/help-gnustep
>>
>
>
>
> --
> Ivan Vučica - iv...@vucica.net
>
> _______________________________________________
> Help-gnustep mailing list
> Help-g...@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.


Ivan Vučica

unread,
Mar 29, 2012, 9:28:47 AM3/29/12
to gusborsa, Help-g...@gnu.org
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.

gusborsa

unread,
Apr 2, 2012, 12:54:19 PM4/2/12
to Help-g...@gnu.org

Hi Fred, your are right, the imageUnfilteredFileTypes method returns the
following types: tiff, tif, pnm, ppm, jpeg, jpg, icns, w32vsr. The code
works OK with a jpeg image but I need the image in png format. I'm a c++
programmer and i'm not sure what steps should I follow. Remember i work on
WinXP. I downloaded the libpng setup (libpng 1.2.37) from sourceforge and I
installed it (In the default installation directory) but the problem
continues.

Thanks,




Fred Kiefer wrote:
>
> On 15.03.2012 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:
>> @"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.
>
> Most likely your version of gui was build without png support. Could you
> please print out the value of:
>
> [NSImage imageUnfilteredFileTypes]
>
> If this array doesn't include "png", then you need to install libpng and
> rebuild gui.
>
> _______________________________________________
> Help-gnustep mailing list
> Help-g...@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-gnustep
>
>
--
View this message in context: http://old.nabble.com/NSImage-problem-tp33513960p33545001.html

Fred Kiefer

unread,
Apr 2, 2012, 4:32:50 PM4/2/12
to gusborsa, Help-g...@gnu.org
Did you install the dev-package for that library as well? You need the
header files plus the .lib file for GNUstep to detect the presence of
libpng and of course you need to rerun ./configure for GNUstep gui
(followed by make and make install.
0 new messages