Created
February 19, 2013 15:59
-
-
Save zeisss/4987149 to your computer and use it in GitHub Desktop.
Create a simple png file with fancy colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"image" | |
"image/png" | |
"image/color" | |
) | |
func paintImage(img *image.RGBA) { | |
for x := 0; x < 200; x++ { | |
for y := 0; y < 200; y++ { | |
img.Set(x, y, color.RGBA{128, uint8(255 - x), uint8(y), 255}) | |
} | |
} | |
} | |
func main() { | |
var i *image.RGBA | |
i = image.NewRGBA(image.Rect(0,0, 200, 200)) | |
paintImage(i) | |
file, ferr := os.OpenFile("test.png", os.O_TRUNC | os.O_CREATE | os.O_WRONLY, 0666) | |
fmt.Println(ferr); | |
err := png.Encode(file, i) | |
file.Sync() | |
fmt.Println(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment