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: mw <email@hidden>
- Date: Fri, 24 Jan 2003 06:46:03 -0500
I didn't think it was allowed to use a line like
NSString* string = @"
http://www.rccl.com/rc/image/vywebcam.jpg";
Wouldn't it have to be
NSString* string = [[NSString alloc]
initWithString:@"
http://www.rccl.com/rc/image/vywebcam.jpg"];
mw
On 1/24/03 12:22 AM, "John Tsombakos" <email@hidden> wrote:
>
I have a small app that is just supposed to download an image from the
>
web and display it in an ImageView. I have an image view in a window,
>
with a button and everything is wired up correctly. (Which is an
>
accomplishment in itself, as I'm on the newbie side of Cocoa). The
>
method the button calls when it's clicked is:
>
>
- (IBAction)getImage:(id)sender
>
{
>
NSString* string = @"http://www.rccl.com/rc/image/vywebcam.jpg";
>
>
if (string) {
>
NSURL* url = [NSURL URLWithString:string];
>
if (url) {
>
NSData *imageData = [url resourceDataUsingCache:NO];
>
if (imageData) {
>
NSImage* image = [[NSImage alloc]
>
initWithData:imageData]; //****
>
if (image) {
>
[voyagerImage setImage:image];
>
} else {
>
NSLog(@"couldn't init image from imageData
>
%@\nLoaded from %@\nReferenced by %@\nwith url %@", imageData, url,
>
string);
>
}
>
} else {
>
NSLog(@"can't init imageData from url %@\n with string
>
%@", url, string);
>
}
>
} else {
>
NSLog(@"can't init url from string %@", url);
>
}
>
} else {
>
NSLog(@"couldn't get a string from sender %@", sender);
>
}
>
}
>
>
Now, it sometimes works, but at the line marked with **** it will
>
generate a message in the debug pane or put the line in the console:
>
"Application transferred too few scanlines".
>
>
I have no idea why! Is this the best way to do this?
>
>
Thanks!
>
>
jt
_______________________________________________
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.