Android 앱을 iOS로 변환하는 데 다시 도움이 필요합니다 ...
다른 게시물에서 언급했듯이 앱은 이미지 처리에 관한 것이며 ColorMatrix를 기반으로합니다. 문제는 Swift가 (내가 아는 한 ...) 4x4 매트릭스 만 지원하고 밝기 또는 대비를 위해 Android에서 5x5 매트릭스를 사용한다는 것입니다.
Android에서 다음은 내 매트릭스입니다.
명도:
float[] brightMatrix = {
1f, 0f, 0f, 0f, 32f,
0f, 1f, 0f, 0f, 32f,
0f, 0f, 1f, 0f, 32f,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f};
대조:
float[] contMatrix = {
1.190f, 0f, 0f, 0f, -12.065f,
0f, 1.190f, 0f, 0f, -12.065f,
0f, 0f, 1.190f, 0f, -12.065f,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f};
하지만 Swift에서 동일한 결과를 얻는 방법을 정말 모르겠습니다.
밝기의 경우 32/255를 나누는이 코드를 사용하여 0.12549 값을 얻으려고했습니다.
func zoeFilter() -> UIImage? {
let inImage = CIImage (image: self)
dynamic let brightFactor = CIFilter (name: "CIColorControls")
brightFactor?.setValue(inImage, forKey: kCIInputImageKey)
brightFactor?.setValue(0.12549, forKey: kCIInputBrightnessKey)
let brightImage = brightFactor?.outputImage
let cgImage = CIContext().createCGImage(brightImage!, from: brightImage!.extent)
return UIImage (cgImage: cgImage!)
}
하지만 결과는 전혀 같지 않습니다 ... iOS에서는 하얀 안개와 같습니다 ...
Contrast에 대해 말하면서 다음 코드를 찾았지만 contFactor?.setValue(1, forKey: kCIInputContrastKey)
1이 중립과 같다는 것만 알고 있는 값으로 Android 매트릭스를 변환하는 것은 불가능합니다 .
func chiaFilter() -> UIImage? {
let inImage = CIImage (image: self)
dynamic let contFactor = CIFilter (name: "CIColorControls")
contFactor?.setValue(inImage, forKey: kCIInputImageKey)
contFactor?.setValue(1, forKey: kCIInputContrastKey)
let contImage = contFactor?.outputImage
let cgImage = CIContext().createCGImage(contImage!, from: contImage!.extent)
return UIImage (cgImage: cgImage!)
}
반면에 Android의 매트릭스는 다음과 같기 때문에 노출을 변경하는 것이 쉽습니다.
float[] expMatrix = {
1.3f, 0f, 0f, 0f, 0f,
0f, 1.3f, 0f, 0f, 0f,
0f, 0f, 1.3f, 0f, 0f,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f};
따라서 Swift에서 정확히 동일한 결과를 얻는 다음 코드를 사용할 수 있습니다.
func liaFilter() -> UIImage? {
let inImage = CIImage (image: self)
dynamic let expoMatrix = CIFilter (name: "CIColorMatrix")
expoMatrix?.setDefaults()
expoMatrix?.setValue(inImage, forKey: kCIInputImageKey)
expoMatrix?.setValue(CIVector (x: 1.3, y: 0, z: 0, w: 0), forKey: "inputRVector")
expoMatrix?.setValue(CIVector (x: 0, y: 1.3, z: 0, w: 0), forKey: "inputGVector")
expoMatrix?.setValue(CIVector (x: 0, y: 0, z: 1.3, w: 0), forKey: "inputBVector")
expoMatrix?.setValue(CIVector (x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
let expoImage = expoMatrix?.outputImage
let cgImage = CIContext().createCGImage(expoImage!, from: expoImage!.extent)
return UIImage (cgImage: cgImage!)
}
너무 혼란 스러워요 ... 알아요 ...하지만 누군가가 Android와 iOS 사이에서 이러한 문제를 해결하는 방법에 대한 아이디어를 가질 수 있다면 좋을 것입니다.
미리 감사드립니다!
프랭크의 답변 후 에디션
다음은 Android에서 다음을 사용하여 필터를 적용한 후입니다.
float[] brightMatrix = {
1f, 0f, 0f, 0f, 32f,
0f, 1f, 0f, 0f, 32f,
0f, 0f, 1f, 0f, 32f,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f};
다음은 iOS에서 필터를 적용하는 동일한 그림입니다.
brightMatrix?.setValue(CIVector (x: 1, y: 0, z: 0, w: 0), forKey: "inputRVector")
brightMatrix?.setValue(CIVector (x: 0, y: 1, z: 0, w: 0), forKey: "inputGVector")
brightMatrix?.setValue(CIVector (x: 0, y: 0, z: 1, w: 0), forKey: "inputBVector")
brightMatrix?.setValue(CIVector (x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
brightMatrix?.setValue(CIVector (x: 32.0/255.0, y: 32.0/255.0, z: 32.0/255.0, w: 0), forKey: "inputBiasVector")
프랭크의 제안 후에 작동하는 최종 솔루션
func zoeFilter() -> UIImage? {
let inImage = CIImage (image: self)
dynamic let SRGBMatrix = CIFilter (name: "CILinearToSRGBToneCurve")
dynamic let brightMatrix = CIFilter (name: "CIColorMatrix")
dynamic let linearMatrix = CIFilter (name: "CISRGBToneCurveToLinear")
SRGBMatrix?.setValue(inImage, forKey: kCIInputImageKey)
let SRGBImage = SRGBMatrix?.outputImage
brightMatrix?.setDefaults()
brightMatrix?.setValue(SRGBImage, forKey: kCIInputImageKey)
brightMatrix?.setValue(CIVector (x: 1, y: 0, z: 0, w: 0), forKey: "inputRVector")
brightMatrix?.setValue(CIVector (x: 0, y: 1, z: 0, w: 0), forKey: "inputGVector")
brightMatrix?.setValue(CIVector (x: 0, y: 0, z: 1, w: 0), forKey: "inputBVector")
brightMatrix?.setValue(CIVector (x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
brightMatrix?.setValue(CIVector (x: 32.0/255.0, y: 32.0/255.0, z: 32.0/255.0, w: 0), forKey: "inputBiasVector")
let brightImage = brightMatrix?.outputImage
linearMatrix?.setDefaults()
linearMatrix?.setValue(brightImage, forKey: kCIInputImageKey)
let linearImage = linearMatrix?.outputImage
let cgImage = CIContext().createCGImage(linearImage!, from: linearImage!.extent)
return UIImage (cgImage: cgImage!)
}
다음과 같이 필터 의 inputBiasVector
매개 변수를 설정하여 밝기 및 대비 매트릭스를 사용할 수 있어야합니다 CIColorMatrix
.
// the first 4 should actually be the default, so you probably don't need to set them explicitly
brightMatrix?.setValue(CIVector(x: 1, y: 0, z: 0, w: 0), forKey: "inputRVector")
brightMatrix?.setValue(CIVector(x: 0, y: 1, z: 0, w: 0), forKey: "inputGVector")
brightMatrix?.setValue(CIVector(x: 0, y: 0, z: 1, w: 0), forKey: "inputBVector")
brightMatrix?.setValue(CIVector(x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
brightMatrix?.setValue(CIVector(x: 32.0/255.0, y: 32.0/255.0, z: 32.0/255.0, w: 0), forKey: "inputBiasVector")
하지만 CIColorControls
필터를 사용 하여 동일한 효과를 얻을 수 없다는 것은 이상합니다 . 예제 이미지를 게시 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다