aiQG's Blog

Happy hacking. Happy developing.

aiQG's GitHub ⛓Links P
Other CTF Swift Developing & Reversing

Swift 学习笔记 (七)

22 February 2019

by aiQG_

//英语不好真遭罪啊

调用ios的摄像头 用摄像头取景 放到控件里 主要用到的是AVFoundation模块 //如果要用到的是系统的相机一般使用UIImagePickerController模块 看看官方文档关于获得多媒体数据, 主要是通过会话(session) 来接收数据输入 处理数据 输出数据的

The main parts of the capture architecture are sessions, inputs, and outputs: Capture sessions connect one or more inputs to one or more outputs. Inputs are sources of media, including capture devices like the cameras and microphones built into an iOS device or Mac. Outputs acquire media from inputs to produce useful data, such as movie files written to disk or raw pixel buffers available for live processing.

在viewDidLoad函数中完成对会话(session)输入输出的设置

//
//  ViewController.swift
//  myiosApp4
//
//  Created by aiQG_ on 2019/2/21.
//  Copyright © 2019 aiQG_. All rights reserved.
//

import UIKit
import AVFoundation //引入模块

class ViewController: UIViewController {

	
	var mySession: AVCaptureSession? //主会话
	
	
	override func viewDidLoad() {
		super.viewDidLoad()
		// Do any additional setup after loading the view, typically from a nib.
		
		
		let session = AVCaptureSession() //创建会话
		let device = AVCaptureDevice.default(_:.builtInWideAngleCamera, for: .video, position: .back) //选择设备
		
		//设置输入
		guard
			let videoInput = try? AVCaptureDeviceInput(device: device!),
			session.canAddInput(videoInput)
			else { return }
		session.addInput(videoInput)
		
		//设置输出
		let videoOutput = AVCaptureVideoDataOutput() //相当于截获输出
		guard session.canAddOutput(videoOutput) else { return }
		session.addOutput(videoOutput)
		
		let ViewLayer = AVCaptureVideoPreviewLayer(session: session) //设置预览层
		let rootLayer = self.myView?.layer //把myView控件作为根控件
		rootLayer?.masksToBounds = true
		ViewLayer.frame = (rootLayer?.bounds)!
		rootLayer?.addSublayer(ViewLayer) //添加层
		
		self.mySession = session //会话传到外部变量中
	}

	//视窗
	@IBOutlet weak var myView: UIView? 
	//按钮
	@IBAction func myButton(_ sender: Any) {
		self.mySession!.startRunning()
	}
}

这里仅仅完成了对会话的输入 输出的设置 并且在控件里显示出来 //下一步要处理session中的数据

Swift

return

email:nrxxmzlrovqw4z3fgeztcncaozuxaltroexgg33n