如何使用UISlider在swift中调整亮度对比度饱和度
在过去的几天里,我一直在寻找如何通过手动操作亮度、对比度、高光、阴影、温暖度等来实现对如何使用UISlider在swift中调整亮度对比度饱和度,swift,uislider,cifilter,ciimage,Swift,Uislider,Cifilter,Ciimage,在过去的几天里,我一直在寻找如何通过手动操作亮度、对比度、高光、阴影、温暖度等来实现对UIImage的过滤。。使用UISlider 这是我目前用来调整亮度的代码 let currentValue = Int(editPictureView.sliderView.value) editPictureView.currentPropertyValue.text = String(currentValue) + " " brightnessFilter.setValue(NSNumber(va
UIImage
的过滤。。使用UISlider
这是我目前用来调整亮度的代码
let currentValue = Int(editPictureView.sliderView.value)
editPictureView.currentPropertyValue.text = String(currentValue) + " "
brightnessFilter.setValue(NSNumber(value: editPictureView.sliderView.value), forKey: "inputBrightness")
outputImage = brightnessFilter.outputImage!
//let imageRef = context.createCGImage(outputImage, from: outputImage.extent)
newUIImage = UIImage(ciImage: outputImage)
editPictureView.selectedImageToEdit.image = newUIImage;
但我收到一个错误,它在展开时发现nil
。
我所要求的只是让你分享你第一次解决这个问题时的感受,如果你能解释一下,你自己也会更好地理解它,或者至少像故事所说的那样。
不过,老实说,先谢谢你
func imageBrightness(imgView : UIImageView , sliderValue : CGFloat, image: UIImage){
let aCGImage = image.cgImage
aCIImage = CIImage(cgImage: aCGImage!)
context = CIContext(options: nil)
brightnessFilter = CIFilter(name: "CIColorControls")
brightnessFilter.setValue(aCIImage, forKey: "inputImage")
brightnessFilter.setValue(sliderValue, forKey: "inputBrightness")
outputImage = brightnessFilter.outputImage!
let cgimg = context.createCGImage(outputImage, from: outputImage.extent)
newUIImage = UIImage(cgImage: cgimg!)
imgView.image = newUIImage
print("brightness")
}
调用此方法并按如下方式传递滑块值和图像:
imageBrightnessEdit(imgView:self.imgView,sliderValue:CGFloat(value),image:imgSelected)
相比之下:
func imageContrast(imgView : UIImageView , sliderValue : CGFloat, image: UIImage){
let aUIImage = image
let aCGImage = aUIImage.cgImage
aCIImage = CIImage(cgImage: aCGImage!)
context = CIContext(options: nil)
contrastFilter = CIFilter(name: "CIColorControls")
contrastFilter.setValue(aCIImage, forKey: "inputImage")
aCIImage = CIImage(cgImage: aCGImage!)
context = CIContext(options: nil)
contrastFilter = CIFilter(name: "CIColorControls")
contrastFilter.setValue(aCIImage, forKey: "inputImage")
contrastFilter.setValue(sliderValue, forKey: "inputContrast")
outputImage = contrastFilter.outputImage!
let cgimg = context.createCGImage(outputImage, from: outputImage.extent)
newUIImage = UIImage(cgImage: cgimg!)
imgView.image = newUIImage
print("contrast")
}
调用此方法并按如下方式传递滑块值和图像:
imageBrightnessEdit(imgView:self.imgView,sliderValue:CGFloat(value),image:imgSelected)
相比之下:
func imageContrast(imgView : UIImageView , sliderValue : CGFloat, image: UIImage){
let aUIImage = image
let aCGImage = aUIImage.cgImage
aCIImage = CIImage(cgImage: aCGImage!)
context = CIContext(options: nil)
contrastFilter = CIFilter(name: "CIColorControls")
contrastFilter.setValue(aCIImage, forKey: "inputImage")
aCIImage = CIImage(cgImage: aCGImage!)
context = CIContext(options: nil)
contrastFilter = CIFilter(name: "CIColorControls")
contrastFilter.setValue(aCIImage, forKey: "inputImage")
contrastFilter.setValue(sliderValue, forKey: "inputContrast")
outputImage = contrastFilter.outputImage!
let cgimg = context.createCGImage(outputImage, from: outputImage.extent)
newUIImage = UIImage(cgImage: cgimg!)
imgView.image = newUIImage
print("contrast")
}
什么是
brightnessFilter
?请在问题中包括其声明。此外,不要使用强制展开选项,除非您100%打开它们,否则它们在您展开它们时将具有非零值。尝试此方法,到目前为止,最有效的方法-特别是性能-是使用(1)三个单独的滑块,分别用于亮度、饱和度和对比度(2)CoreImage CiColorControl(),以及(3)使用使用GPU的GLKView
显示CIImage输出。上面的链接对有关内存消耗的答案进行了评论,使用UIImage
或任何与UIKit相关的工具都会导致性能低下。什么是brightnessFilter
?请在问题中包括其声明。此外,不要使用强制展开选项,除非您100%打开它们,否则它们在您展开它们时将具有非零值。尝试此方法,到目前为止,最有效的方法-特别是性能-是使用(1)三个单独的滑块,分别用于亮度、饱和度和对比度(2)CoreImage CiColorControl(),以及(3)使用使用GPU的GLKView
显示CIImage输出。上面的链接对有关内存消耗的答案进行了评论,使用UIImage
或任何与UIKit相关的工具都会导致性能低下。好吧,我现在有个问题,我正在使用UISlider来更改亮度和对比度,只是在实现了给定的代码之后,我的UISlider会滞后,你介意给我一些建议,关于如何解决这个问题。也许你的imgae分辨率很高。您可以使用dispatch thread。好的,我现在有一个问题,我正在使用UISlider来更改亮度和对比度,但在实现上面的给定代码后,我的UISlider会滞后,您介意给我一些建议,告诉我如何解决这个问题。可能是您的imgae分辨率很高。您可以使用分派线程。