我想使用 surface.At() 获取像素数据
package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
)
func main() {
var (
winTitle string = "Surface At"
winWidth, winHeight int32 = 1200, 720
window *sdl.Window
renderer *sdl.Renderer
surface *sdl.Surface
)
window, _ = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, winWidth, winHeight, sdl.WINDOW_SHOWN)
renderer, _ = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
renderer.SetDrawColor(35, 80, 0, 180)
renderer.Clear()
renderer.Present()
surface, _ = window.GetSurface()
for x := 0; x < int(winWidth); x++ {
for y := 0; y < int(winHeight); y++ {
color := surface.At(x, y)
fmt.Println(color, "color", x, "x", y, "y")
}
}
sdl.Delay(1000)
sdl.Quit()
}
{35, 80, 0, 180} color 0 x 0 y但它不是返回每个像素的实际颜色 ( ),而是一直返回{0 0 0 255} color 0 x 0 y到最后。
如何解决这个问题?或者也许有什么东西可以用来代替surface.At()?
holdtom
相关分类