简体   繁体   English

iOS-使用AVCaptureSession拍摄图像

[英]iOS - Take image using AVCaptureSession

I want to take picture with AVCaptureSession for iOS, I can take a picture but it takes like a print screen and save it on PhotoLibrary, How can I get real picture not print screen and also save it on view not in a library, would you please help me in this implementation, 我想使用iOS的AVCaptureSession拍照,我可以拍照,但是需要像打印屏幕一样,然后将其保存在PhotoLibrary中,如何获得不是打印屏幕的真实照片,也可以将其保存在不在库中的视图中,请帮助我实施

Thanks in advance! 提前致谢!

Here is my code: 这是我的代码:

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];
}

You need to investigate and use AVCaptureStillImageOutput . 您需要研究和使用AVCaptureStillImageOutput Apple supplies documentation showing how to take an image with the camera. Apple提供的文档显示了如何使用相机拍摄图像。

You are explicitly saving the image with UIImageWriteToSavedPhotosAlbum - you don't need to do that. 您正在使用UIImageWriteToSavedPhotosAlbum明确保存图像-无需这样做。 Just use the image in an image view or similar. 只需在图像视图或类似视图中使用该image


Or if I misunderstood, see How to take a screenshot programmatically . 或者,如果我误解了,请参见如何以编程方式拍摄屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM