我想用适用于 iOS 的 AVCaptureSession 拍照,我可以拍照,但它像打印屏幕一样拍摄并将其保存在 PhotoLibrary 中,我怎样才能获得真实图片而不是打印屏幕并将其保存在 View 中而不是在库中,你能帮我实现这个吗,
提前致谢!
这是我的代码:
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
。苹果用品documentation展示如何使用相机拍摄图像。
您正在使用 UIImageWriteToSavedPhotosAlbum
明确保存图像 - 您不需要这样做。只需在 ImageView 或类似 View 中使用 image
。
或者如果我误解了,请参阅 How to take a screenshot programmatically .
关于iphone - iOS - 使用 AVCaptureSession 拍摄图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258616/