找出触摸点的屏幕亮度

问题描述 投票:0回答:1

有没有办法找出触摸点处像素的亮度,例如,如果我想知道屏幕上每个形状内的像素亮度?

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)
    }
  }
}
swift swiftui screen pixel brightness
1个回答
1
投票

据我所知,目前还没有办法做到这一点。不过,您可以尝试使用 Core Graphics,但您必须将形状转换为 CGImage。我建议你看一下 Core Graphics 文档 Core Graphics

© www.soinside.com 2019 - 2024. All rights reserved.