lif*_*ott 3 ios cifilter ciimage swift
将 CIFilter 应用于相机拍摄的照片后,拍摄的图像会缩小并重新定位。
我在想,如果我能够获得原始图像的大小和方向,它会相应地缩放并将图像视图固定到屏幕的角落。但是,这种方法没有任何改变,并且不知道我可以正确地将图像缩放到屏幕的全尺寸的方法。
func applyBloom() -> UIImage {
let ciImage = CIImage(image: image) // image is from UIImageView
let filteredImage = ciImage?.applyingFilter("CIBloom",
withInputParameters: [ kCIInputRadiusKey: 8,
kCIInputIntensityKey: 1.00 ])
let originalScale = image.scale
let originalOrientation = image.imageOrientation
if let image = filteredImage {
let image = UIImage(ciImage: image, scale: originalScale, orientation: originalOrientation)
return image
}
return self.image
}
Run Code Online (Sandbox Code Playgroud)
图片说明:图片截取并截屏,图片缩小后留空。
尝试这样的事情。代替:
func applyBloom() -> UIImage {
let ciInputImage = CIImage(image: image) // image is from UIImageView
let ciOutputImage = ciInputImage?.applyingFilter("CIBloom",
withInputParameters: [kCIInputRadiusKey: 8, kCIInputIntensityKey: 1.00 ])
let context = CIContext()
let cgOutputImage = context.createCGImage(ciOutputImage, from: ciInputImage.extent)
return UIImage(cgImage: cgOutputImage!)
}
Run Code Online (Sandbox Code Playgroud)
发生的事情是这样的 - 获取过滤/输出 CIImage,并使用 CIContext,编写输入 CIImage 大小的 CGImage。
最后,一个建议。如果您尝试使用 CIFilter 来显示图像的“近实时”更改(如照片编辑器),请考虑使用 CIImages 和GLKViewUIImages 和UIImageView. 前者使用设备 GPU 而不是 CPU。
| 归档时间: |
|
| 查看次数: |
1929 次 |
| 最近记录: |