Displaying jpeg images
Displaying jpeg images
- Subject: Displaying jpeg images
- From: email@hidden
- Date: Sat, 9 Jun 2001 14:11:37 -0400
Hello,
I'm trying to write a program which fetches a jpeg off a web page and
displays it. I made a window with an NSImageView connected to an outlet
called MyImage, and a button which sends a message -refreshImage: whenever
it's clicked. Then I wrote the following code:
- (IBAction)refreshImage:(id)sender
{
NSImage *img;
NSURL *url = [NSURL URLWithString: @"
http://www.somesite.com/cgi-
bin/image.pl"];
NSLog(@"url = %@", url);
img = [[NSImage alloc] initWithContentsOfURL: url];
NSLog(@"img = %@", img);
[MyImage setImage: img];
[img release];
}
However, it doesn't work-- initWithContentsOfURL: keeps returning nil, and
so the image doesn't get displayed. What am I doing wrong?
(I noticed in the documentation for NSImage that jpeg isn't mentioned at
all, only tiff and Windows bmp. Does that mean I should be using a
different class? Also, would the fact that the URL has a .pl extension
instead of .jpg or .jpeg have anything to do with it?)
--
Cliff Crawford
http://www.sowrong.org/