• 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: Getting Image from Web and Displaying it problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Image from Web and Displaying it problem


  • Subject: Re: Getting Image from Web and Displaying it problem
  • From: "John Tsombakos" <email@hidden>
  • Date: Fri, 24 Jan 2003 09:57:53 -0500

I did change the image loading code to use this. It's now:
- (IBAction)getImage:(id)sender
{
NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.rccl.com/rc/image/vywebcam.jpg";]];
if (image) {
[voyagerImage setImage:image];
[image release];
} else {
NSLog(@"Could not load image");
}
}

I haven't seen the error message, but it could be just it's been loading fine this morning. I'd still like to be able to trap the bad-load.

One this I also did notice - I didn't have the release in there originally, and I was watching the app using 'top' in a terminal window. Every time I clicked the button, the memory would go up. (Remember, Cocoa semi-newbie here) I guessed that the image was being retained by the Imageview and that I could release it like I do above. It didn't crash, and the memory didn't creep up this time, so I guess I assumed correctly.

(I've read pretty much all the articles on retain-release and a couple Cocoa books, and understand the concept - it's just figuring out actually when you should release, like above yes you need to release the image, but the string is autoreleased and I don't have to do it explicitly)

Thanks again!

On Fri, 24 Jan 2003 14:27:33 +0100
David Remahl <email@hidden> wrote:
Nope, it is perfectly ok to do:

NSString *str = @"whatever";

I'm not sure what the original poster's problem might be. The code looks ok. Are you sure the image you are downloading isn't corrupt?

You could also try;

NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString@"http://www.rccl.com/rc/image/vywebcam.jpg";]];

The image will then be downloaded from the URL automatically.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Getting Image from Web and Displaying it problem (From: David Remahl <email@hidden>)

  • Prev by Date: Nib Stripping
  • Next by Date: Re: Peer To Peer Design
  • Previous by thread: Re: Getting Image from Web and Displaying it problem
  • Next by thread: Re: Getting Image from Web and Displaying it problem
  • Index(es):
    • Date
    • Thread