Reputation: 2435
I have some code that loads an image file off the web and puts it in an image view. The problem is it works with everything except Google Charts. This is frustrating because I was relying on this to graph data for my app. Heres the url I need to load: Click to see my test chart. Im not sure why NSImage seems to refuse to load this when it works with everything elese. If you know why or have a work-around any help is appreciated.
Here's some sample code I found that I'm using to load the images:
NSURL *imageURL = [NSURL URLWithString:@"http://chart.apis.google.com/chart?cht=p3&chs=700x400&chd=t:20,20,20,20,20&chl=A|B|C|D|E&chco=66FF33,3333CC"];
NSLog(@"url");
NSData *imageData = [imageURL resourceDataUsingCache:NO];
NSLog(@"data");
NSImage *imageFromBundle = [[NSImage alloc] initWithData:imageData];
(Note: This code will load any image except a chart)
Thanks
Upvotes: 2
Views: 5022
Reputation: 3069
Or just use
stringByAddingPercentEscapesUsingEncoding:
Then you don't have to hard-code all the various escapes. See Description
Peter Deserves a Thumbs up.
Upvotes: 1
Reputation: 66
This is failing because | is not a valid characted for URLs. You must replace the | characters in your URL with the escape code: %7C . The following URL will work:
Upvotes: 4