-
Notifications
You must be signed in to change notification settings - Fork 60
/
simplest.go
42 lines (33 loc) · 636 Bytes
/
simplest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"image"
"os"
"log"
"image/png"
)
/*
#cgo CFLAGS: -O3
#include <stdint.h>
#include "heatmap.h"
*/
import "C"
func main() {
imageData := make([]uint8,256*256*4)
heatmap := C.heatmap_new(256, 256)
C.heatmap_add_point(heatmap, 100, 100)
C.heatmap_render_default_to(heatmap, (*C.uchar)(&imageData[0]))
C.heatmap_free(heatmap)
img := image.NewNRGBA(image.Rect(0, 0, 256, 256))
img.Pix = imageData
f, err := os.Create("image.png")
if err != nil {
log.Fatal(err)
}
if err := png.Encode(f, img); err != nil {
f.Close()
log.Fatal(err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
}