iOS - 使用AVCaptureSession拍摄图像

时间:2013-10-08 21:18:27

标签: iphone ios objective-c xcode

我想用AVCaptureSession for iOS拍照,我可以拍照但是它需要一个打印屏幕并将其保存在PhotoLibrary上,如何才能获得真实的图片而不是打印屏幕并将其保存在视图而非图书馆中,请你帮我解决这个问题,

提前致谢!

这是我的代码:

CGImageRef UIGetScreenImage(void);
- (void) scanButtonPressed {

CGImageRef screen = UIGetScreenImage();(what should I use here instead of 
UIGetScreenImage)
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);


// Save the captured image to photo album
UIImageWriteToSavedPhotosAlbum(image, self,   
@selector(image:didFinishSavingWithError:contextInfo:), nil);

}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void
*)contextInfo
{
UIAlertView *alert;

if (error)
    alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                       message:@"Unable to save image to Photo Album."
                                      delegate:self cancelButtonTitle:@"Ok"
                             otherButtonTitles:nil];
else {
CoverCapturePhoto *c = [[CoverCapturePhoto alloc] init];
[self.navigationController pushViewController:c animated:YES];
    [c.captureImage setImage:image];
}

[alert show];
}

1 个答案:

答案 0 :(得分:1)

您需要调查并使用AVCaptureStillImageOutput。 Apple提供了显示如何使用相机拍摄图像的documentation

您明确使用UIImageWriteToSavedPhotosAlbum保存图像 - 您不需要这样做。只需在图片视图中使用image或类似。


如果我误解了,请参阅How to take a screenshot programmatically