在 Go 中,image.Image 介面表示包含像素資料的影像。要透過texImage2D 方法從影像中取得像素陣列以在OpenGL ES 2.0 中使用,可以使用以下步驟:
type Pixel struct { R int G int B int A int }
func rgbaToPixel(r uint32, g uint32, b uint32, a uint32) Pixel { return Pixel{int(r / 257), int(g / 257), int(b / 257), int(a / 257)} }
func getPixels(img image.Image) ([][]Pixel, error) { bounds := img.Bounds() width, height := bounds.Max.X, bounds.Max.Y var pixels [][]Pixel for y := 0; y <ol start="4"><li>Load映像並呼叫 getPixels 取得像素array:</li></ol><pre class="brush:php;toolbar:false">file, err := os.Open("./image.png") if err != nil { fmt.Println("Error: File could not be opened") os.Exit(1) } defer file.Close() pixels, err := getPixels(file) if err != nil { fmt.Println("Error: Image could not be decoded") os.Exit(1) }
以上是如何從 OpenGL ES 2.0 的 Go `image.Image` 中檢索像素數組?的詳細內容。更多資訊請關注PHP中文網其他相關文章!