• 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: 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.

  • Follow-Ups:
    • Re: Getting Image from Web and Displaying it problem
      • From: "John Tsombakos" <email@hidden>
    • Re: Getting Image from Web and Displaying it problem
      • From: "John Tsombakos" <email@hidden>
    • Re: Getting Image from Web and Displaying it problem
      • From: "John Tsombakos" <email@hidden>
References: 
 >Re: Getting Image from Web and Displaying it problem (From: mw <email@hidden>)

  • Prev by Date: Re: DSP framework for Cocoa
  • Next by Date: Getting multiple sliders to interact in an NSMartix
  • 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