views:

44

answers:

1

I am trying to use the following code to take screen shots from my uiimagePickerController

UIGraphicsBeginImageContext(imagePicker.view.bounds.size);
[self.imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It shows everything except what is capturing from the camera, i see the cancel button, take photo buttom. Instead of what is displaying on the camera it's capturing a black screen, is there any way around this? or a better way to automatically capture an image from camera every 1 seconds?

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection
{ 
    UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
    UIImageView *img = [[UIImageView alloc] initWithImage:image];
    [img setFrame:CGRectMake(0, 0, 320, 480)];
    [self.view addSubview:img];
    [img release];
}
+1  A: 

You want to use the new (in OS 4) AVFoundation APIs.

Try this page for some info:

http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html

Amorya
thanks, it seems to be the best way, but o far the data i receive cannot be converted to a uiimage. I'll update
aryaxt
The sample code in the link I posted should help. Part way down is a line that says < Add your code here that uses the image >. At that point yiu have a uiimage to do what you like with.
Amorya
Yes everything works fine and i receive captureOutput, but when i convert it to a uiimage and create an imageview and add it to my view, the uiimageview doesn't display the picture, i think somehow the data is interrupted. Does this suppose to work on iphone 3g? since iphone 3g doesn't allow video recording.
aryaxt
the problem is that it's blocking the main thread, so after start capturing the ui is locked, i tried running it on a thread, and doesn't seem like it's thread safe.
aryaxt