From: AceVest Date: Sun, 19 Jan 2020 12:09:24 +0000 (+0800) Subject: add bit pic tool X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/roff.7.ps?a=commitdiff_plain;h=b3188c7905a08277649598f8c217e1a88c967d6b;p=acecode.git add bit pic tool --- diff --git a/tools/comm/bitpic.go b/tools/comm/bitpic.go new file mode 100644 index 0000000..8ec3475 --- /dev/null +++ b/tools/comm/bitpic.go @@ -0,0 +1,97 @@ +/* + * ------------------------------------------------------------------------ + * File Name: bitpic.go + * Author: Zhao Yanbai + * 2020-01-19 12:06:24 星期日 CST + * Description: none + * ------------------------------------------------------------------------ + */ +package main +import ( + "fmt" + "image" + "image/jpeg" + "os" + "log" + "image/color" +) + +func getKey(x, y, divCntX, divCntY int) string { + xp := x / divCntX + yp := y / divCntY + + s := fmt.Sprintf("%v_%v", xp, yp) + + return s +} + +func main() { + defer fmt.Println("Program Exited...") + + raw_pic_reader, err := os.Open("./a.jpg") + if err != nil { + log.Fatal(err) + } + defer raw_pic_reader.Close() + + m, _, err := image.Decode(raw_pic_reader) + if err != nil { + log.Fatalf("Decode: %v\n", err) + } + + + bounds := m.Bounds() + + img := image.NewRGBA(bounds) + + data := make(map[string][]color.Color) + + const divCntX = 12 + const divCntY = 12 + + for y := bounds.Min.Y; y