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&#39;s the case, I&#39;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&#39=
;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"&#39;courier =
new&#39;, monospace">NSLog(@&quot;%@&quot;, [NSImage imageUnfilteredFileTyp=
es]);<br></font><br>If it doesn&#39;t print out an array (I&#39;m not sure =
if GNUstep does), try this:</div>

<div><font face=3D"&#39;courier new&#39;, monospace">for(NSString * type in=
 [NSImage imageUnfilteredFileTypes])</font></div><div><font face=3D"&#39;co=
urier new&#39;, monospace">=C2=A0 NSLog(@&quot;- %@&quot;, type);</font></d=
iv><div>

<br></div><div>or if your compiler doesn&#39;t support &quot;fast enumerati=
on&quot;, try this:</div><div><font face=3D"&#39;courier new&#39;, monospac=
e">NSEnumerator *e =3D [[NSImage imageUnfilteredFileTypes] objectEnumerator=
];</font></div>

<div><font face=3D"&#39;courier new&#39;, monospace">for(NSString * type =
=3D [e nextObject]; type; type =3D [e nextObject])</font></div><div><div><f=
ont face=3D"&#39;courier new&#39;, monospace">=C2=A0 NSLog(@&quot;- %@&quot=
;, type);</font></div>

</div><div><br></div><div>If you don&#39;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">&lt;<a href=3D"mailto:[email protected]">[email protected]=
</a>&gt;</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&#39;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>
&gt;<br>
&gt; Loading of the image has failed for some reason.<br>
&gt;<br>
&gt; If you are correctly mentioning the file name in &quot;GNUmakefile&quo=
t; as a<br>
&gt; resource (and hence it gets copied inside the .app), try instantiating=
 the<br>
&gt; image using method +[NSImage imageNamed:].<br>
&gt;<br>
&gt; This should work:<br>
&gt; NSImage *myImage =3D [NSImage imageNamed:@&quot;imagen&quot;]; // auto=
released<br>
&gt;<br>
&gt; Optionally retain it; the object returned is autoreleased.<br>
&gt;<br>
&gt; Alternatively get the path like this:<br>
&gt; NSString *path =3D [[NSBundle mainBundle] pathForResource:@&quot;image=
n&quot; ofType:@<br>
&gt; &quot;png&quot;];<br>
&gt; NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile:path]; //=
<br>
&gt; retained already<br>
&gt;<br>
&gt; It&#39;s a bad idea to reference to things using an absolute path. Alw=
ays try<br>
&gt; to refer to paths using some API, even when referring to paths inside =
the<br>
&gt; app bundle. When you move the app to a new platform, you&#39;ll be gla=
d you<br>
&gt; did.<br>
&gt;<br>
&gt; If nothing of the above helps, try using a different .png to verify yo=
ur<br>
&gt; GNUstep installation is capable of decoding the PNG file format.<br>
&gt;<br>
&gt; On Thu, Mar 15, 2012 at 23:58, gusborsa &lt;<a href=3D"mailto:gusborsa=
@yahoo.com.mx">[email protected]</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Hello, I=C2=B4m trying to create a NSImage object from a png type =
image. My<br>
&gt;&gt; code:<br>
&gt;&gt;<br>
&gt;&gt; NSImage *myImage =3D [[NSImage alloc] initWithContentsOfFile:<br>
&gt;&gt; @&quot;c:/MiProyect/Resources/imagen.png&quot;];<br>
&gt;&gt;<br>
&gt;&gt; but this method returns &quot;nil&quot;, the description message f=
rom the myImage<br>
&gt;&gt; object returns (NULL).<br>
&gt;&gt;<br>
&gt;&gt; I Verified the path with the fileExistsAtPath (NSFileManager) meth=
od and<br>
&gt;&gt; it&#39;s OK. I&#39;m working on WinXP.<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&gt;&gt; <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>
&gt;&gt; Sent from the GNUstep - Help mailing list archive at Nabble.com.<b=
r>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Help-gnustep mailing list<br>
&gt;&gt; <a href=3D"mailto:[email protected]">[email protected]</a><b=
r>
&gt;&gt; <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>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Ivan Vu=C4=8Dica - <a href=3D"mailto:[email protected]">[email protected]<=
/a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Help-gnustep mailing list<br>
&gt; <a href=3D"mailto:[email protected]">[email protected]</a><br>
&gt; <a href=3D"https://lists.gnu.org/mailman/listinfo/help-gnustep" target=
=3D"_blank">https://lists.gnu.org/mailman/listinfo/help-gnustep</a><br>
&gt;<br>
&gt;<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==--