iphone - iOS - 使用 AVCaptureSession 拍摄图像

标签 iphone ios objective-c xcode

我想用适用于 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/

相关文章:

iphone - 如何格式化要使用 arrayWithContentsOfFile 读取的文本文件

ios - Autolayouts 设置纵向和横向 View iOS

ios - iOS-Facebook应用测试用户-发布操作

iphone - 如何延迟显示Game Center的弹窗?

iphone - App Store 的本地化价格

objective-c - 在Cocoa中,NSDateFormatter提供了一个dateFromString : method for parsing strings into date objects. NSByteCountFormatter有类似的东西吗?

iphone - iOS 上的 WebP 图片格式

iphone - 允许用户从免费版本中购买付费应用程序版本?

iphone - 使用 ALAssetsLibrary 从 iphone 相册中读取图像

iOS:UIView 不会停留在状态栏后面