0

I am writing an OS X app, with cocoa, and trying to figure out how to get a web-cam still image from an axiscam at this url:

http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg&timestamp=

Using the dispatch/queue/block suggested here:

Getting Image from URL Objective C

it will return the html code of the page.

What is the suggested way to get the image data from the web-cam and not the page? Since there isn't a direct link to a jpg image, it is a bit confusing.

I was able to make this work in C# - Save Webcam Image From Website which is my answer/question at the bottom - looks like I forgot my old accnt and started a new one.

Community
  • 1
  • 1
Mike Weber
  • 311
  • 2
  • 16
  • i suggest you to get url of video stream, as it shows on the website, you can directly stream and show video on IOS device using `MPMoviePlayerController`, dont need to download image and from that page you cant get anything – Dipen Panchasara May 03 '13 at 04:25
  • My intent is to collect a still image at a defined interval. Also, the video stream is only good for 20 seconds and requires a refresh to continue. The intended platform is OS X not iOS. – Mike Weber May 03 '13 at 15:10

1 Answers1

0

Looks like I figured this out.

Headers need to be set up as follows:

self.bweHeader = @"http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg?timestamp=";
self.bweImage = @"http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=";
self.bweHost = @"bigwatersedge.axiscam.net";

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL       URLWithString:[self.bweImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];

[theRequest setHTTPMethod:@"GET"];
[theRequest addValue:self.bweHost forHTTPHeaderField:@"Host"];
[theRequest addValue:self.bweHeader forHTTPHeaderField:@"Referer"];

NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&returnError];

NSImage *camImage = [[NSImage alloc] initWithData:data];

[self.imageView setImage:camImage];
[self.imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
Mike Weber
  • 311
  • 2
  • 16