我試圖調整一個大小爲128x128的CVPixelBuffer。我正在使用750x750。我目前正在使用CVPixelBuffer創建一個新的CGImage,然後將其重新調整爲CVPixelBuffer。這裏是我的代碼:調整一個CVPixelBuffer的大小
func getImageFromSampleBuffer (buffer:CMSampleBuffer) -> UIImage? {
if let pixelBuffer = CMSampleBufferGetImageBuffer(buffer) {
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
let context = CIContext()
let imageRect = CGRect(x: 0, y: 0, width: 128, height: 128)
if let image = context.createCGImage(ciImage, from: imageRect) {
let t = CIImage(cgImage: image)
let new = t.applying(transformation)
context.render(new, to: pixelBuffer)
return UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .right)
}
}
return nil
}
我也試着縮放CIImage然後將其轉換:
let t = CIImage(cgImage: image)
let transformation = CGAffineTransform(scaleX: 1, y: 2)
let new = t.applying(transformation)
context.render(new, to: pixelBuffer)
但是,這也不能工作。
任何幫助表示讚賞。謝謝!
請在這裏查找'vImageScale_ARGB8888':https://stackoverflow.com/a/10063006/2567725 –