【发布时间】:2016-10-16 11:05:52
【问题描述】:
我正在尝试返回已更改的像素及其颜色。以下 func 工作正常,但它没有给我所需的 255,255,255 值。是否可以将其转换为所需的格式?
我已经看过这里的文档 -> https://golang.org/pkg/image/color/
我也手动尝试了不同的转换,但我无法让它工作。有人知道如何在 golang 中转换它吗?
type Pixel struct {
x, y int
r, g, b, a uint32
}
func diffImages(imgOne *image.RGBA, imgTwo *image.RGBA) []Pixel {
var pixels []Pixel
bounds := imgOne.Bounds()
diff := false
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, a := imgOne.At(x, y).RGBA()
rt, gt, bt, at := imgTwo.At(x, y).RGBA()
if r != rt || g != gt || b != bt || a != at {
diff=true
}
if diff == true {
pixel := new(Pixel)
pixel.x = x
pixel.y = y
pixel.r = rt
pixel.g = gt
pixel.b = bt
pixel.a = at
pixels = append(pixels, *pixel)
}
diff = false
}
}
return pixels
}
如果有比我愿意接受的更好或更快的方法来获得所需的输出。
注意:我是新手。
【问题讨论】:
-
请举例说明您尝试了什么、输出了什么以及您希望看到什么。