有没有办法找出触摸点处像素的亮度,例如,如果我想知道屏幕上每个形状内的像素亮度?
struct ContentView: View {
@State var brightness = 0.0
var body: some View {
VStack {
Rectangle()
.frame(width: 100,height: 100)
.foregroundColor(.black)
Circle()
.frame(width: 100,height: 100)
.foregroundColor(.gray)
RoundedRectangle(cornerRadius: 30)
.frame(width: 100,height: 100)
.foregroundColor(.gray.opacity(0.5))
Text("brightness = \(brightness)")
.font(.largeTitle)
}
}
}
据我所知,目前还没有办法做到这一点。不过,您可以尝试使用 Core Graphics,但您必须将形状转换为 CGImage。我建议你看一下 Core Graphics 文档 Core Graphics