[英]iOS - Take image using AVCaptureSession
我想使用iOS的AVCaptureSession拍照,我可以拍照,但是需要像打印屏幕一样,然后将其保存在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];
}
您需要研究和使用AVCaptureStillImageOutput
。 Apple提供的文档显示了如何使用相机拍摄图像。
您正在使用UIImageWriteToSavedPhotosAlbum
明确保存图像-无需这样做。 只需在图像视图或类似视图中使用该image
。
或者,如果我误解了,请参见如何以编程方式拍摄屏幕截图 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.