Re: NSImage problem
Ivan Vučica <[email protected]> Thu, 29 Mar 2012 15:28:47 +0200
| Newsgroups | gmane.comp.lib.gnustep.user |
|---|---|
| Message-ID | <CAGPLYoQPr4nOFCMT8N1to-zwKa_4jtOpH_qCuTtnww3xmTaKCA@mail.gmail.com> |
--===============2866998906093166631== Content-Type: multipart/alternative; boundary=f46d043085e205083704bc61b6ab --f46d043085e205083704bc61b6ab Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 =3D [[NSImage imageUnfilteredFileTypes] objectEnumerator]; for(NSString * type =3D [e nextObject]; type; type =3D [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 <[email protected]> wrote: > > Thank you Ivan, I was following yours advices: > > 1) I made sure that the image was in the app's resources directory (throu= gh > 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=C4=8Dica 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 =3D [NSImage imageNamed:@"imagen"]; // autoreleased > > > > Optionally retain it; the object returned is autoreleased. > > > > Alternatively get the path like this: > > NSString *path =3D [[NSBundle mainBundle] pathForResource:@"imagen" > ofType:@ > > "png"]; > > NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile:path]; // > > retained already > > > > It's a bad idea to reference to things using an absolute path. Always t= ry > > to refer to paths using some API, even when referring to paths inside t= he > > 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 you= r > > GNUstep installation is capable of decoding the PNG file format. > > > > On Thu, Mar 15, 2012 at 23:58, gusborsa <[email protected]> wrote: > > > >> > >> Hello, I=C2=B4m trying to create a NSImage object from a png type imag= e. My > >> code: > >> > >> NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile: > >> @"c:/MiProyect/Resources/imagen.png"]; > >> > >> but this method returns "nil", the description message from the myImag= e > >> object returns (NULL). > >> > >> I Verified the path with the fileExistsAtPath (NSFileManager) method a= nd > >> 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=C4=8Dica - [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 > --=20 Ivan Vu=C4=8Dica - [email protected] --f46d043085e205083704bc61b6ab Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,<div><br></div><div>If that's the case, I'll repeat and expand u= pon what Fred said: the cause might be that your version of gnustep-gui was= built without PNG support.</div><div><br></div><div>Please follow Fred'= ;s instruction of listing the contents of the array containing supported da= ta types.</div> <div><br></div><div>This should work:</div><div><font face=3D"'courier = new', monospace">NSLog(@"%@", [NSImage imageUnfilteredFileTyp= es]);<br></font><br>If it doesn't print out an array (I'm not sure = if GNUstep does), try this:</div> <div><font face=3D"'courier new', monospace">for(NSString * type in= [NSImage imageUnfilteredFileTypes])</font></div><div><font face=3D"'co= urier new', monospace">=C2=A0 NSLog(@"- %@", type);</font></d= iv><div> <br></div><div>or if your compiler doesn't support "fast enumerati= on", try this:</div><div><font face=3D"'courier new', monospac= e">NSEnumerator *e =3D [[NSImage imageUnfilteredFileTypes] objectEnumerator= ];</font></div> <div><font face=3D"'courier new', monospace">for(NSString * type = =3D [e nextObject]; type; type =3D [e nextObject])</font></div><div><div><f= ont face=3D"'courier new', monospace">=C2=A0 NSLog(@"- %@"= ;, type);</font></div> </div><div><br></div><div>If you don't see png listed in the output, NS= Image cannot load a png under your installation.</div><div><br></div><div><= div class=3D"gmail_quote">On Wed, Mar 28, 2012 at 23:09, gusborsa <span dir= =3D"ltr"><<a href=3D"mailto:[email protected]">[email protected]= </a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><br> Thank you Ivan, I was following yours advices:<br> <br> 1) I made sure that the image was in the app's resources directory (thr= ough<br> the Gnumakefile).<br> 2) The NSBundle is a very nice class, but the results were the same, the<br= > NSImage pointer returned by the alloc method was NULL.<br> 3) the same result instansiating the image using imageNamed.<br> <br> I appreciate your help.<br> <div><div class=3D"h5"><br> <br> Ivan Vu=C4=8Dica wrote:<br> ><br> > Loading of the image has failed for some reason.<br> ><br> > If you are correctly mentioning the file name in "GNUmakefile&quo= t; as a<br> > resource (and hence it gets copied inside the .app), try instantiating= the<br> > image using method +[NSImage imageNamed:].<br> ><br> > This should work:<br> > NSImage *myImage =3D [NSImage imageNamed:@"imagen"]; // auto= released<br> ><br> > Optionally retain it; the object returned is autoreleased.<br> ><br> > Alternatively get the path like this:<br> > NSString *path =3D [[NSBundle mainBundle] pathForResource:@"image= n" ofType:@<br> > "png"];<br> > NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile:path]; //= <br> > retained already<br> ><br> > It's a bad idea to reference to things using an absolute path. Alw= ays try<br> > to refer to paths using some API, even when referring to paths inside = the<br> > app bundle. When you move the app to a new platform, you'll be gla= d you<br> > did.<br> ><br> > If nothing of the above helps, try using a different .png to verify yo= ur<br> > GNUstep installation is capable of decoding the PNG file format.<br> ><br> > On Thu, Mar 15, 2012 at 23:58, gusborsa <<a href=3D"mailto:gusborsa= @yahoo.com.mx">[email protected]</a>> wrote:<br> ><br> >><br> >> Hello, I=C2=B4m trying to create a NSImage object from a png type = image. My<br> >> code:<br> >><br> >> NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile:<br> >> @"c:/MiProyect/Resources/imagen.png"];<br> >><br> >> but this method returns "nil", the description message f= rom the myImage<br> >> object returns (NULL).<br> >><br> >> I Verified the path with the fileExistsAtPath (NSFileManager) meth= od and<br> >> it's OK. I'm working on WinXP.<br> >><br> >> Thanks<br> >> --<br> >> View this message in context:<br> >> <a href=3D"http://old.nabble.com/NSImage-problem-tp33513960p335139= 60.html" target=3D"_blank">http://old.nabble.com/NSImage-problem-tp33513960= p33513960.html</a><br> >> Sent from the GNUstep - Help mailing list archive at Nabble.com.<b= r> >><br> >><br> >> _______________________________________________<br> >> Help-gnustep mailing list<br> >> <a href=3D"mailto:[email protected]">[email protected]</a><b= r> >> <a href=3D"https://lists.gnu.org/mailman/listinfo/help-gnustep" ta= rget=3D"_blank">https://lists.gnu.org/mailman/listinfo/help-gnustep</a><br> >><br> ><br> ><br> ><br> > --<br> > Ivan Vu=C4=8Dica - <a href=3D"mailto:[email protected]">[email protected]<= /a><br> ><br> > _______________________________________________<br> > Help-gnustep mailing list<br> > <a href=3D"mailto:[email protected]">[email protected]</a><br> > <a href=3D"https://lists.gnu.org/mailman/listinfo/help-gnustep" target= =3D"_blank">https://lists.gnu.org/mailman/listinfo/help-gnustep</a><br> ><br> ><br> <br> --<br> </div></div>View this message in context: <a href=3D"http://old.nabble.com/= NSImage-problem-tp33513960p33544855.html" target=3D"_blank">http://old.nabb= le.com/NSImage-problem-tp33513960p33544855.html</a><br> <div class=3D"HOEnZb"><div class=3D"h5">Sent from the GNUstep - Help mailin= g list archive at Nabble.com.<br> <br> <br> _______________________________________________<br> Help-gnustep mailing list<br> <a href=3D"mailto:[email protected]">[email protected]</a><br> <a href=3D"https://lists.gnu.org/mailman/listinfo/help-gnustep" target=3D"_= blank">https://lists.gnu.org/mailman/listinfo/help-gnustep</a><br> </div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>= Ivan Vu=C4=8Dica -=C2=A0<a href=3D"mailto:[email protected]" target=3D"_blank= ">[email protected]</a><div><div><div><br></div></div></div><br> </div> --f46d043085e205083704bc61b6ab-- --===============2866998906093166631== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Help-gnustep mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-gnustep --===============2866998906093166631==--