Re: Getting Image from Web and Displaying it problem
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.