• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
<newbie> Can't use NSImage initWithContentsOfURL:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

<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


  • Follow-Ups:
    • Re: <newbie> Can't use NSImage initWithContentsOfURL:
      • From: Dan Wood <email@hidden>
  • Prev by Date: Re: How do I replace the "Do you want to save changes...?" sheet?
  • Next by Date: You're Invited to a Mac OS X APPLE HELP Kitchen
  • Previous by thread: Re: Load NIB in dynamically loaded bundle.
  • Next by thread: Re: <newbie> Can't use NSImage initWithContentsOfURL:
  • Index(es):
    • Date
    • Thread