swift-06

01-下载解压zip包

// 1.获取要下载文件的URL

guard let url = URL(string: "https://file.qf.56.com/f/style/static/gift/m/v2/zip/motianlun.zip") else {

return

}

// 2.获取下载的文件存放的路径

let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory, in: .userDomainMask)

// 3.开始进行下载

Alamofire.download(url, to: destination).response { (response : DefaultDownloadResponse) in

// 3.1.获取zip所在的目录

// URL : URL Scheme + Path

guard let zipPath = response.destinationURL?.path else {

return

}

print(zipPath)  这个是带有包名的路径

// 3.2.获取unzip存放的目录---删除最后的包名-解压的路径

let unzipPath = (zipPath as NSString).deletingLastPathComponent

// 3.3.解压文件

SSZipArchive.unzipFile(atPath: zipPath, toDestination: unzipPath)

}}

02.采集视频  采集音频  音视频的写入---代理中执行

03 GpuImage使用

// 1.获取到需要处理的图片

let image = imageView.image!

// 2.创建GPUImagePicture

let processImage = GPUImagePicture(image: image)

// 3.添加对应的滤镜

let blurFilter = GPUImageGaussianBlurFilter()

blurFilter.blurRadiusInPixels = 5

blurFilter.texelSpacingMultiplier = 10

// 4.将滤镜添加到processImage

processImage?.addTarget(blurFilter)

// 5.使用滤镜处理下一次显示的该图片

blurFilter.useNextFrameForImageCapture()

processImage?.processImage()

// 6.获取最新的图片

imageView.image = blurFilter.imageFromCurrentFramebuffer()

}

GpuImage添加其他滤镜

GPUImageStillCamera的使用

fileprivate var camera : GPUImageStillCamera!

fileprivate var filter : GPUImageBrightnessFilter!

var isFirst : Bool = true

@IBAction func startCapturing() {

if isFirst {

// 1.创建GPUImage中的相机 100 : 1

let camera = GPUImageStillCamera(sessionPreset: AVCaptureSessionPresetHigh, cameraPosition: .front)

camera?.outputImageOrientation = .portrait

self.camera = camera

// 2.添加滤镜

let filter = GPUImageBrightnessFilter()

camera?.addTarget(filter)

self.filter = filter

// 3.创建GPUImageView对象

let gpuImageView = GPUImageView(frame: view.bounds)

view.insertSubview(gpuImageView, at: 0)

filter.addTarget(gpuImageView)

isFirst = false

}

// 4.开始采集

camera?.startCapture()

}

@IBAction func stopCapturing() {

camera.stopCapture()

}

@IBAction func rotateCamera() {

camera.rotateCamera()

}

@IBAction func takePhoto() {

camera.capturePhotoAsImageProcessedUp(toFilter: filter) { (image :  UIImage?, error : Error?) in

UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)

}

}

你可能感兴趣的:(swift-06)