• 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
Re: <newbie> Can't use NSImage initWithContentsOfURL:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: <newbie> Can't use NSImage initWithContentsOfURL:


  • Subject: Re: <newbie> Can't use NSImage initWithContentsOfURL:
  • From: Dan Wood <email@hidden>
  • Date: Tue, 20 Nov 2001 14:42:41 -0800

Inexplicably, several classes that read from URLs only work with local (file://) URLs. Try using NSURL or NSURLHandle to get some NSData and go from there.


On Monday, November 19, 2001, at 01:36 PM, Steve Bird wrote:

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
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev



--
Dan Wood
email@hidden
http://www.karelia.com/
http://www.bikealameda.org/
Mac OS X Developer: Online Resume: http://www.karelia.com/resume.html


  • Follow-Ups:
    • Re: <newbie> Can't use NSImage initWithContentsOfURL:
      • From: Steve Bird <email@hidden>
    • Re: <newbie> Can't use NSImage initWithContentsOfURL:
      • From: Scott Anguish <email@hidden>
References: 
 ><newbie> Can't use NSImage initWithContentsOfURL: (From: Steve Bird <email@hidden>)

  • Prev by Date: Re: Anchor in TextView HTML
  • Next by Date: Re: Rects and points...
  • Previous by thread: <newbie> Can't use NSImage initWithContentsOfURL:
  • Next by thread: Re: <newbie> Can't use NSImage initWithContentsOfURL:
  • Index(es):
    • Date
    • Thread