UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Image.grayscale(1.0) not working for me?

Forums > SwiftUI

I'm playing around with the Image.grayscale() modifier and for some reason, a value of 1.0 doesn't seem to give me a fully desaturated image. Values from 0 up to 0.99 look as expected, but as I go to 1.0 I get more saturation again:

Any idea what's wrong here? The problem also happens when running the app in the Simulator, not just in Preview.

3      

Don't you mean to use .saturation instead of .greyscale ?

3      

I did mean .grayscale(). Why? Shouldn't I use that?

What's the difference between the two? What differentiates them other than that their scales are reversed (.grayscale(0) is no effect, .saturation(1) is no effect)?

It seems that .saturation() can be driven beyond 1.0 to oversaturate an image but that's not something I want to do.

3      

I also couldn't get grayscale to work. I ended up using saturation instead. If you've figured it out let me know.

struct Test: View {
    let isGray: Bool

    var body: some View {
        VStack {
            Image(systemName: "questionmark")
            Text("WTF")
        }
        .saturation(isGray ? 0.0 : 1.0)
    }
}

3      

Why not just use .opacity on the image? ..... or did you specifically want to try something different?

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.