您的位置:首页 > 编程语言 > Go语言

使用Go语言画图,基础图

2014-04-23 12:22 706 查看
这个事例使用了一个简单的画图,并将其写入到http的包里面,只需几步, 打开http://localhost:999/即可看到, 其它还在研究当中, 研究出来自然跟大家分享.

package main

import (
"image"
"image/color"
"image/draw"
"image/png"
"net/http"

)

var (
blue  color.Color = color.RGBA{0, 0, 255, 255}
picwidth int = 640
picheight int = 480

)

// 大家可以查看这个网址看看这个image包的使用方法 http://golang.org/doc/articles/image_draw.html
func main() {
http.HandleFunc("/", TTT)
http.ListenAndServe(":999", nil)

}

func TTT(rw http.ResponseWriter, req *http.Request) {

//创建一个图像

m := image.NewRGBA(image.Rect(0, 0, picwidth , picheight)) //*NRGBA (image.Image interface)
// 填充蓝色,并把其写入到m
draw.Draw(m, m.Bounds(), &image.Uniform{blue}, image.ZP, draw.Src)
//以png编码格式,并将m写入到 rw里面去
png.Encode(rw, m) //Encode writes the Image m to w in PNG format.

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Go语言 Golang 图片