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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.