Average colors in part of KFImage #1675
markzakharyan
started this conversation in
General
Replies: 2 comments
-
Hi, Sorry for the late reply. Got crazy busy recently. Maybe you want to use the completion handler instead. Here is some sample code for you: var body: some View {
let imageURL = "https://images.pexels.com/photos/3225531/pexels-photo-3225531.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"
return KFImage(URL(string: imageURL))
.onSuccess { result in
let image = result.image
let cropped = image.kf.crop(to: CGSize(width: 100, height: 100), anchorOn: .zero)
let filter = Filter { input in
let inputImage = input
let extentVector = CIVector(x: inputImage.extent.origin.x, y: inputImage.extent.origin.y, z: inputImage.extent.size.width, w: inputImage.extent.size.height)
guard let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: extentVector]) else { return nil }
return filter.outputImage
}
let whatYouWant: UIImage = cropped.kf.apply(filter)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have a KFImage processor I made that does exactly what I want with averaging the color values in a section of the image. Instead of replacing the original image, how am I able to extract an RGB value from this? My code is below:
As you can see, I'm unable to extract an actual color value from the KFImage. Rather, I'm changing the current image. Is there a way I can leave the original image untouched, and get a color value from it?
I'm new to Swift, but I did spend quite a bit of time on this to no avail :(
Beta Was this translation helpful? Give feedback.
All reactions