Go 语言画蓝色矩形

package main

import (

	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"os"

	//"os"
)

func main() {
    
    

	rectangle := "rectangle.png"//这个是图片的名字
	m := image.NewRGBA(image.Rect(0, 0, 640, 480))//生成了一个画布
	blue := color.RGBA{
    
    0, 0, 255, 255}//生成了一个颜色
	draw.Draw(m, m.Bounds(), &image.Uniform{
    
    blue}, image.ZP, draw.Src)
	file, err := os.Create(rectangle)
	if err != nil {
    
    
		log.Fatalf("failed create file: %s", err)
	}
	png.Encode(file, m)//这个是把画布和文件结合起来。





}

猜你喜欢

转载自blog.csdn.net/zhuiyunzhugang/article/details/121242663