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

查看:93
本文介绍了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天全站免登陆