iOS 以编程方式拍照 [英] iOS taking photo programmatically

查看:38
本文介绍了iOS 以编程方式拍照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是可能的,在一些应用程序中看到了这一点(我相信 iGotYa 是最著名的).我知道如何设置所有照片、保存照片和所有内容.但是如何以编程方式完成呢?只需让用户单击某个按钮(在常规视图控制器中),它就会使用前置摄像头自动拍照并保存(或不保存,只需将其作为 UIImage 获取)

I know this is possible, saw this in some apps (iGotYa is I believe the most famous). I know how to set up everything for taking photos, saving it and everything. But how can it be done programmatically? just having the user click some button (in the regular view controller) and it will automatically take a picture using the front camera and saving it (or not, just getting it as a UIImage)

谢谢!

推荐答案

这个很简单,直接使用AVFoundation参考指南:

This is very simple, just use the AVFoundation reference guide:

https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html

如果您不希望用户看到预览输入,您可以跳过代码的设置预览层部分.

If you don't want the user to see the preview input you can just skip the set preview layer part of the code.

更详细.

1)您使用 AVFoundation 设置捕获配置.

1)You set your capture configuration using the AVFoundation.

  • 将相机输入设置为正面,关闭闪光灯等.

2)您跳过设置视频预览层的部分.

2)You SKIP the part where the video preview layer is set.

3) 每当您想要拍摄照片时,您都可以调用 captureStillImageAsynchronouslyFromConnection:completionHandler: 方法.

3)You call the captureStillImageAsynchronouslyFromConnection:completionHandler: method whenever you want the picture to be taken.

注意:如果您不希望听到闪光灯等声音,那么您可能会侵犯某些国家/地区(例如日本)的用户权限.我知道的一种解决方法是捕获视频的一帧(不触发闪光灯).

Note: If you want the flash to not be heard and such then you might be violating the user rights in some countries (japan for example). One workaround I know of to do so is by capturing a frame of a video (does not trigger flash).

这篇关于iOS 以编程方式拍照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆