Go では、image.Image インターフェイスはピクセル データを含む画像を表します。 texImage2D メソッドを介して OpenGL ES 2.0 で使用する image.Image からピクセル配列を取得するには、次の手順を使用できます:
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>画像をロードし、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 中国語 Web サイトの他の関連記事を参照してください。