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: David Remahl <email@hidden>
- Date: Fri, 24 Jan 2003 14:27:33 +0100
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.
Perhaps the problem is that the image is replaced during the file
transfer? I mean, if it comes from a webcam, that could be a
possibility.
/ Regards, David
On Friday, January 24, 2003, at 12:46 PM, mw wrote:
>
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.
_______________________________________________
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.