//go:build ignore // gen-header 生成 NSIS 安装向导 header.bmp(150x57, 24-bit BMP)。 // 设计:深绿渐变背景 + 右侧白色描边正圆(内含 Z 字), // 正圆直径与高度匹配,不存在拉伸变形问题。 // 手写 24-bit BMP 编码(Go 1.26 已移除 image/bmp 标准库)。 package main import ( "encoding/binary" "fmt" "image" "image/color" "math" "os" ) const ( W = 150 H = 57 ) // 渐变背景色:左 #0F5132(深绿)→ 右 #04281A(更暗) func bgColor(x int) color.RGBA { t := float64(x) / float64(W-1) return color.RGBA{ R: uint8(0x0F + (0x04-0x0F)*t), G: uint8(0x51 + (0x28-0x51)*t), B: uint8(0x32 + (0x1A-0x32)*t), A: 255, } } func main() { img := image.NewRGBA(image.Rect(0, 0, W, H)) // 背景渐变 for y := 0; y < H; y++ { for x := 0; x < W; x++ { img.Set(x, y, bgColor(x)) } } // 右侧正圆(中心 (121,28),半径 24,描边 3px) cx, cy, rad, lw := 121.0, 28.0, 24.0, 3.0 white := color.RGBA{R: 255, G: 255, B: 255, A: 255} for y := 0; y < H; y++ { for x := 0; x < W; x++ { d := math.Hypot(float64(x)-cx, float64(y)-cy) if math.Abs(d-rad) <= lw/2.0 { img.Set(x, y, white) } } } // 圆内 "Z" 字(白色线段,粗 2px) pts := [][2]float64{ {cx - 12, cy - 12}, {cx + 12, cy - 12}, {cx - 12, cy + 12}, {cx + 12, cy + 12}, } for i := 0; i < len(pts)-1; i++ { drawLine(img, pts[i][0], pts[i][1], pts[i+1][0], pts[i+1][1], 2.0, white) } // 左侧装饰:细白色竖线分隔(半透明效果用混合色) sep := color.RGBA{R: 200, G: 220, B: 210, A: 255} for y := 12; y < H-12; y++ { img.Set(86, y, sep) } // 手写 24-bit BMP 输出(bottom-up, 每行 4 字节对齐) if err := writeBMP("header.bmp", img); err != nil { fmt.Println("write failed:", err) os.Exit(1) } fmt.Printf("header.bmp generated: %dx%d (%d bytes)\n", W, H, rowSize(W)*H+54) } func rowSize(w int) int { return ((w*3 + 3) / 4) * 4 } func writeBMP(path string, img *image.RGBA) error { f, err := os.Create(path) if err != nil { return err } defer f.Close() bounds := img.Bounds() w, h := bounds.Dx(), bounds.Dy() rowPad := rowSize(w) fileSize := 54 + rowPad*h // BITMAPFILEHEADER (14) hdr := make([]byte, 14) binary.LittleEndian.PutUint16(hdr[0:2], 0x4D42) // 'BM' binary.LittleEndian.PutUint32(hdr[2:6], uint32(fileSize)) binary.LittleEndian.PutUint32(hdr[10:14], 54) // pixel data offset // BITMAPINFOHEADER (40) dib := make([]byte, 40) binary.LittleEndian.PutUint32(dib[0:4], 40) // header size binary.LittleEndian.PutUint32(dib[4:8], uint32(w)) binary.LittleEndian.PutUint32(dib[8:12], uint32(h)) binary.LittleEndian.PutUint16(dib[12:14], 1) // planes binary.LittleEndian.PutUint16(dib[14:16], 24) // bpp binary.LittleEndian.PutUint32(dib[16:20], 0) // no compression binary.LittleEndian.PutUint32(dib[20:24], uint32(rowPad*h)) binary.LittleEndian.PutUint32(dib[24:28], 2835) // 72dpi binary.LittleEndian.PutUint32(dib[28:32], 2835) if _, err := f.Write(hdr); err != nil { return err } if _, err := f.Write(dib); err != nil { return err } // 像素数据(bottom-up: 从最后一行开始) row := make([]byte, rowPad) for y := h - 1; y >= 0; y-- { for x := 0; x < w; x++ { c := img.RGBAAt(x, y) row[x*3+0] = c.B row[x*3+1] = c.G row[x*3+2] = c.R } if _, err := f.Write(row); err != nil { return err } } return nil } // drawLine 粗线段绘制 func drawLine(img *image.RGBA, x0, y0, x1, y1, width float64, c color.RGBA) { steps := int(math.Max(math.Abs(x1-x0), math.Abs(y1-y0))) + 1 for i := 0; i <= steps; i++ { t := float64(i) / float64(steps) x := x0 + (x1-x0)*t y := y0 + (y1-y0)*t r := int(width / 2) for dy := -r; dy <= r; dy++ { for dx := -r; dx <= r; dx++ { px, py := int(x)+dx, int(y)+dy if px >= 0 && px < W && py >= 0 && py < H { img.Set(px, py, c) } } } } }