簡體   English   中英

無法將CIImage保存到相機膠卷-Swift 3

[英]Cannot save CIImage to camera roll - Swift 3

我正在嘗試將濾鏡應用於CIImage,該濾鏡是從AVCaptureSession的像素緩沖區創建的,然后將其保存到相機膠卷中。

這是我的代碼

        let image = CIImage(cvPixelBuffer: pixelBuffer)

        let filter = CIFilter(name: "CISepiaTone")
        filter?.setValue(image, forKey: kCIInputImageKey)
        filter?.setValue(0.1, forKey: kCIInputIntensityKey)

        let newImage = UIImage(ciImage: (filter?.outputImage)!)

        print ("new image: \(newImage)")

        UIImageWriteToSavedPhotosAlbum(newImage, self,    #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)

這不會引發任何錯誤,並且在調用image(_:didFinishSavingWithError:contextInfo :)時沒有錯誤

但是圖像沒有出現在我的媒體庫中。 非常混淆! 任何幫助表示贊賞。

謝謝。

我也遇到了同樣的情況並解決了這個問題。

我的方法是:首先將其轉換為CGImage,然后將CGImage對象轉換為UIImage,在這種情況下,您是否可以成功將處理后的圖像保存到相機膠卷中。

這是代碼。

let input = CIImage(image: MyImageView.image!)
let filter = PinkyFilter() // My custom filter
filter.setValue(input, forKey: kCIInputImageKey)
let context = CIContext() // Prepare for create CGImage
let cgimg = context.createCGImage(filter.outputImage, from: filter.outputImage.extent)
let output = UIImage(cgImage: cgimg!)

然后輸出是一個可保存的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM