<newbie> Can't use NSImage initWithContentsOfURL:
<newbie> Can't use NSImage initWithContentsOfURL:
- Subject: <newbie> Can't use NSImage initWithContentsOfURL:
- From: Steve Bird <email@hidden>
- Date: Mon, 19 Nov 2001 16:36:12 -0500
Why does case 'A' work and case 'B' fail (the returned image is nil) ?
myURLA = [ NSURL
URLWithString:@"
http://www.Culverson.com/WebTealLogoWithMotto.jpg" ];
myNSDataA = [[[ NSData alloc] initWithContentsOfURL: myURLA ]
autorelease];
myNSImageA = [[[NSImage alloc] initWithData: myNSDataA ] autorelease];
[myNSImageViewA setImage: myNSImageA ];
myURLB = [ NSURL
URLWithString:@"
http://www.Culverson.com/WebTealLogoWithMotto.jpg" ];
myNSImageB = [[[NSImage alloc] initWithContentsOfURL: myURLB ]
autorelease];
[myNSImageViewB setImage: myNSImageB ];
In other words, why do I have to go through an NSDATA step?
The URL's are known valid, as is evidenced by the A case working.
The NSIMAGE docs (Yes, I have RTFM) say this:
----------------------
- (id)initWithContentsOfURL:(NSURL *)anURL
Initializes the receiver, a newly allocated NSImage instance, with the
contents of the URL anURL.
After finishing the initialization, this method returns self. However, if
at least one image representation can't be created from the contents of
anURL, the receiver is freed and nil is returned.
----------------------
The NSDATA docs say this:
----------------------
- (id)initWithContentsOfURL:(NSURL *)anURL
Description forthcoming.
----------------------
Since NIL is being returned in the failing case, one answer would be that
the NSIMAGE can't figure out the type.
But if it can't figure out the type from the URL, then why can it do it
from the NSDATA?
I've tried other URL values, same behavior.
If I use [[NSImage alloc] initWithContentsOfFile:
@"WebTealLogoWithMotto.jpg ], all is as expected.
Any clues?
-------------------------------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com (toll free) 1-877-676-8175