Convert Image to Greyscale #2879
-
I have looked everywhere for an answer to this, apparently its not a problem that has ever existed, or its so easy that noone has asked a question on it! I have the following code which I would have though would scale the image to greyscale (based on a standard scaling formula), however it come out with a green tint. I have tried multiple approaches but not found anything that seems to easily greyscale the image. func (s *screen) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
op.ColorScale.Scale(0.299, 0.587, 0.114, 1)
screen.DrawImage(s.currentImage, op)
} Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can use https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2/colorm#ColorM.ChangeHSV
See also |
Beta Was this translation helpful? Give feedback.
-
Thank you! That has solved the issue. Although For anyone in future that has the same issue and would like the see the updated code, I have pasted it below. func (s *screen) Draw(screen *ebiten.Image) {
op := &colorm.DrawImageOptions{}
var c colorm.ColorM
c.ChangeHSV(0, 0, 1)
colorm.DrawImage(screen, s.currentImage, c, op)
} |
Beta Was this translation helpful? Give feedback.
You can use
ColorM
.https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2/colorm#ColorM.ChangeHSV
See also
examples/hsv