• 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
Displaying jpeg images
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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/


  • Follow-Ups:
    • Re: Displaying jpeg images (from HD)
      • From: "Giovanni A. D." <email@hidden>
    • Re: Displaying jpeg images
      • From: Richard Schreyer <email@hidden>
    • Re: Displaying jpeg images
      • From: "Michael P. Rogers" <email@hidden>
  • Prev by Date: keyboard events
  • Next by Date: Re: NSSplitView divider image
  • Previous by thread: keyboard events
  • Next by thread: Re: Displaying jpeg images
  • Index(es):
    • Date
    • Thread