I'm trying to convert an image to full grayscale with SwiftUI and am using .grayscale()
.
The documentation says the following for this method:
The intensity of grayscale to apply. Values closer to 0.0 are more colorful, and values closer to 1.0 are less colorful.
However, when I use .grayscale(1.0)
a full-color image is returned but .grayscale(0.99)
returns a full grayscale image.
Is this just a bug with SwiftUI or am I misunderstanding how this method works?
Unfortunately this is not possible. Grayscale images do not contain sufficient information to create a color image. In instances where you see B&W/Grayscale images converted to color, this has been done manually in an application such as photoshop.
I'm guessing its a bug, but you can also use .saturation(0.0)
and .saturation(1.0)
to get the effect you're looking for.
I was having the same error and I found this:
https://developer.apple.com/documentation/swiftui/text/grayscale(_:)
Seems like you have to use 0.9995 instead of 1 to achieve the gray behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With