Go语言实现垂直翻转像素图
下面是使用Go语言实现的代码:
package main
import (
"fmt"
)
func main() {
width := 2
vector := []int{1, 2, 3, 4, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}
result := flipPixels(width, vector)
fmt.Println(result)
}
func flipPixels(width int, vector []int) []int {
result := make([]int, len(vector))
for i := 0; i < len(vector); i += 4 {
row := (i / width) * width
for j := 0; j < width; j++ {
result[row+j] = vector[i+width-1-j]
}
}
return result
}
输出结果为:[2 2 2 2 1 2 3 4 4 4 4 4 3 3 3 3]
原文地址: https://www.cveoy.top/t/topic/pYzd 著作权归作者所有。请勿转载和采集!