我有這個奇怪的問題,我無法解決。如果我用我的應用程序拍攝照片並將CIFilter應用於其上,則一切正常,但如果我拍攝另一張照片並應用相同的濾鏡,則我的應用程序會崩潰而不會出現任何錯誤。但奇怪的是,我可以使用相機膠捲上的圖像進行相同的處理,並且該應用程序完美無缺。如果我將CIFilter應用於CIImage,應用程序崩潰 - Swift 2.0
let context = CIContext(options: nil)
func processImage(image: UIImage, colors: Int) -> UIImage{
var img1:CIImage = CIImage(image: image)!
img1 = img1.imageByApplyingFilter("CIPhotoEffectMono", withInputParameters:["inputImage" : img1])
img1 = img1.imageByApplyingFilter("CISharpenLuminance", withInputParameters: ["inputImage" : img1])
img1 = img1.imageByApplyingFilter("CIColorPosterize", withInputParameters: ["inputImage" : img1, "inputLevels" : colors])
img1 = img1.imageByApplyingFilter("CIColorControls", withInputParameters: ["inputImage" : img1, "inputSaturation" : 1, "inputBrightness": 0.2, "inputContrast": 1.5 //8
])
img1 = img1.imageByApplyingFilter("CIHighlightShadowAdjust", withInputParameters: ["inputImage" : img1, "inputHighlightAmount": 6, "inputShadowAmount": 0])
img1 = img1.imageByApplyingFilter("CIColorPosterize", withInputParameters: ["inputImage" : img1, "inputLevels" : 3])
let cgImg = context.createCGImage(img1, fromRect: img1.extent)
let uiImg = UIImage(CGImage: cgImg, scale: 1.0, orientation: image.imageOrientation)
print("x")
return uiImg
}
我已經看過了內存的使用,如果我用圖像從相機我的應用程序使用了約40%,而它崩潰,:
//CAMERA
@IBOutlet weak var imageView: UIImageView!
var selectedImage: UIImage!
@IBAction func rollButtonPressed(sender: UIBarButtonItem) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .PhotoLibrary
self.presentViewController(picker, animated: true, completion: nil)
}
@IBAction func cameraButtonPressed(sender: UIBarButtonItem) {
if UIImagePickerController.isSourceTypeAvailable(.Camera){
let camera = UIImagePickerController()
camera.delegate = self
camera.allowsEditing = false
camera.sourceType = UIImagePickerControllerSourceType.Camera
camera.showsCameraControls = true
camera.cameraOverlayView?.layer.borderWidth = 3
camera.cameraOverlayView?.layer.borderColor = UIColor.redColor().CGColor
camera.cameraOverlayView?.frame = CGRectMake(self.view.frame.minX, self.view.frame.midY - self.view.frame.width/8, self.view.frame.width, self.view.frame.width/4)
self.presentViewController(camera, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
selectedImage = (info[UIImagePickerControllerOriginalImage] as! UIImage)
for var i = 2; i <= 10; i++ {
imageView.image = processImage(selectedImage, colors: i)
}
}
引起該問題的函數但如果我從相機膠捲中選擇圖像,我只能獲得最大。 8%的RAM使用率。
如果你知道爲什麼,如果你能留下答案,我會非常高興。
一個問題。如果我做'imageData = UIImagePNGRepresentation(processImage(selectedImage !,顏色:2))''imageData'爲零。 – NMAC427