Re: NSImage problem
Ivan Vučica <[email protected]> Fri, 16 Mar 2012 16:13:04 +0100
| Newsgroups | gmane.comp.lib.gnustep.user |
|---|---|
| Message-ID | <CAGPLYoRebP1O9CxssJD=5KHDg+JLt+JePegTyJFDdNzuvzy31g@mail.gmail.com> |
--===============7579187901552577195== Content-Type: multipart/alternative; boundary=f46d0407129df3a1ae04bb5da6ca --f46d0407129df3a1ae04bb5da6ca Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 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=C2=B4m trying to create a NSImage object from a png type image. = My > code: > > NSImage *myImage =3D [[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 > --=20 Ivan Vu=C4=8Dica - [email protected] --f46d0407129df3a1ae04bb5da6ca Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Loading of the image has failed for some reason.<div><br></div><div>If you = are correctly mentioning the file name in "GNUmakefile" as a reso= urce (and hence it gets copied inside the .app), try instantiating the imag= e using method +[NSImage imageNamed:].</div> <div><br></div><div>This should work:</div><div>NSImage *myImage =3D [NSIma= ge imageNamed:@"imagen"]; // autoreleased<br><div><br></div><div>= Optionally retain it; the object returned is autoreleased.</div><div><br> </div><div>Alternatively get the path like this:</div><div>NSString *path = =3D [[NSBundle mainBundle] pathForResource:@"imagen" ofType:@&quo= t;png"];</div><div>NSImage *myImage =3D [[NSImage alloc] initWithConte= ntsOfFile:path]; // retained already</div> <div><br></div><div>It's a bad idea to reference to things using an abs= olute path. Always try to refer to paths using some API, even when referrin= g to paths inside the app bundle. When you move the app to a new platform, = you'll be glad you did.</div> <div><br></div><div>If nothing of the above helps, try using a different .p= ng to verify your GNUstep installation is capable of decoding the PNG file = format.</div><div><br><div class=3D"gmail_quote">On Thu, Mar 15, 2012 at 23= :58, gusborsa <span dir=3D"ltr"><<a href=3D"mailto:[email protected]= " target=3D"_blank">[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> Hello, I=C2=B4m trying to create a NSImage object from a png type image. My= 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 from the m= yImage<br> object returns (NULL).<br> <br> I Verified the path with the fileExistsAtPath (NSFileManager) method and<br= > it's OK. I'm working on WinXP.<br> <br> Thanks<br> <span><font color=3D"#888888">--<br> View this message in context: <a href=3D"http://old.nabble.com/NSImage-prob= lem-tp33513960p33513960.html" target=3D"_blank">http://old.nabble.com/NSIma= ge-problem-tp33513960p33513960.html</a><br> Sent from the GNUstep - Help mailing list archive at Nabble.com.<br> <br> <br> _______________________________________________<br> Help-gnustep mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Help-gnustep@gnu.= org</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> </font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b= r>Ivan Vu=C4=8Dica -=C2=A0<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</a><div><div><div><br></div></div></div><br> </div></div> --f46d0407129df3a1ae04bb5da6ca-- --===============7579187901552577195== 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 --===============7579187901552577195==--