• 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
NSImage with URL - why doesn't it work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage with URL - why doesn't it work?


  • Subject: NSImage with URL - why doesn't it work?
  • From: Yuhui <email@hidden>
  • Date: Sun, 2 Sep 2001 12:42:39 -0500

Hi

I use the following code to get an NSImage from a JPEG file on the Web:

NSImage *myImage;
myImage = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.wisc.edu/wiscinfo/images/bascom.jpg";]];
if (myImage == nil)
NSLog(@"nil");

However, myImage always returns 'nil', even though the URL is valid. I tested this with other images, e.g. http://images.amazon.com/images/P/6303407188.01.MZZZZZZZ.jpg, and myImage came back 'nil' as well.

On the other hand, when I tested with a JPEG in my app's build folder, e.g.

myImage = [[NSImage alloc] initWithContentsOfFile:@"47.jpg"];
if (myImage == nil)
NSLog(@"nil");

myImage would display the correct image. I changed my JPEG's file name to 4.7.jpg to test if NSImage was confused by file extensions, but the image displayed correctly too, so I know that my problem has nothing to do with the presence of extra periods in the file name.

I use the [NSURL URLWIthString:] method for HTML files e.g.

NSString *myString;
myString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/";]];

and my app would get the HTML file correctly, i.e. I can save myString to a text file and it'll contain the exact contents of the HTML file at www.apple.com.


Does anyone know what's wrong with my NSImage code?

Thanks
Yuhui


  • Prev by Date: Re: How to get cursor on an NSTextView to go to the top...
  • Next by Date: Re: Linking seperate nibs
  • Previous by thread: Re: How to get cursor on an NSTextView to go to the top...
  • Next by thread: CFRunLoop
  • Index(es):
    • Date
    • Thread