1

我正在开发基于“相机/照片”的应用程序。

应用程序启动 (sideMenu) :MainView 是带有相机按钮的NavigationCTRL中的普通 VC。
点击它会推动一个新的 VC。
这个很正常,但是里面有这样的东西:

let captureSession: AVCaptureSession = AVCaptureSession()
var currentCaptureDevice: AVCaptureDevice?
var deviceInput: AVCaptureDeviceInput?
var stillCameraOutput: AVCaptureStillImageOutput?
var previewLayer: AVCaptureVideoPreviewLayer?

所以它是一个自定义的相机视图控制器。
我可以——通过这种方式——获得更好的用户体验。
然后我可以拍照(从库中,或通过点击拍摄按钮(在打开/关闭某些功能 [定时器、高清、闪光灯 ..] 之后)。

当它拍照时,我使用prepareForSegue方法将捕获的图像发送到下一个 VC :

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == Constants.Segues.CameraToFiltersSegue {
        var filterVC = segue.destinationViewController as! MYCLASSVC
        filterVC.originalImage = pictureImage
    }
}

然后,它推送了新的 VC 并且...
我收到了这条消息:BSXPCMessage 收到消息错误:连接中断

当前的 VC 包含:

  • an imageView (UIImageView) : 上一张图片
  • 一个小的集合视图,其中包含来自原始(CIFilter)的小(缩略图)过滤图片

在这个视图中仅此而已。但我有这个消息。
这个消息呢?
我应该以不同的方式做某事吗?

这就是我设置过滤器的方式:

//At the top of the class
//EAGLRenderingAPI.OpenGLES2 but maybe EAGLRenderingAPI.OpenGLES3??
static let contextFast = CIContext(EAGLContext: EAGLContext(API: EAGLRenderingAPI.OpenGLES2), options: [kCIContextWorkingColorSpace: NSNull(), kCIContextUseSoftwareRenderer: false])

//In my static method (one of the parameter is "originalImage")
var ciimage: CIImage = CIImage(image: originalImage)
var imageFilter = CIFilter(name: "CIPhotoEffectInstant")
filter.setValue(ciimage, forKey: kCIInputImageKey)
let cgimg = contextFast.createCGImage(imageFilter.outputImage, fromRect: imageFilter.outputImage.extent())
return UIImage(CGImage: cgimg, scale: 1.0, orientation: image.imageOrientation)

这段代码运行得很快!我不知道消息是从哪里来的。

那么,如果您有任何想法或更多帮助?

4

1 回答 1

2

如果我在下一行之前返回 nil,我永远不会收到消息。

let cgimg = contextFast.createCGImage(filter.outputImage, fromRect: filter.outputImage.extent())

如果我使用软件渲染器选项的正常上下文为 "true" :

let context = CIContext(options: [kCIContextUseSoftwareRenderer: true])

消息消失。我试图将此选项放入我的最后一个 fastContext 但没有任何改变。
所以它来自使用的 context,但是在正常的 context 中,渲染的时间要长 x5 (也许更多)。在快速的上下文中,我的 collectionView 从来没有慢过。我什至没有看到重新加载数据。
但是在正常的上下文中,它是可见的。

在基本的相机/照片应用程序中,Apple 也有同样的东西。一张图片和一个带有原始图片缩略图但已过滤的collectionView!他们是怎么做到的?我们甚至看不到正在加载的项目。

于 2015-08-07T08:25:04.227 回答