map-dots/imaging/canvas.go

23 lines
522 B
Go
Raw Permalink Normal View History

2023-08-11 14:32:44 +01:00
package imaging
import (
"image"
"image/color"
)
// CreateCanvas creates a new image canvas with the specified width and height
func createCanvas(width, height int) *image.RGBA {
canvas := image.NewRGBA(image.Rect(0, 0, width, height))
clearCanvas(canvas, color.Black)
return canvas
}
func clearCanvas(img *image.RGBA, backgroundColor color.Color) {
bounds := img.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
img.Set(x, y, backgroundColor)
}
}
}