实现了控制台启动后自动隐藏

This commit is contained in:
2025-10-31 17:29:14 +08:00
parent 22b4402737
commit 8d41c1ba62
6 changed files with 82 additions and 59 deletions

View File

@@ -1,50 +1,42 @@
package main
import (
"image"
"os"
"github.com/icza/icox" // 替换为icox库
"github.com/nfnt/resize"
)
func main() {
// 1. 读取PNG文件
inputPath := "manifest/images/logo.png" // 输入PNG路径
outputPath := "manifest/images/favicon.ico" // 输出ICO路径
pngFile, err := os.Open(inputPath)
if err != nil {
panic("无法打开PNG文件: " + err.Error())
}
defer pngFile.Close()
// 2. 解码PNG为image.Image对象
img, _, err := image.Decode(pngFile)
if err != nil {
panic("PNG解码失败: " + err.Error())
}
// 3. 定义ICO需要包含的尺寸常见尺寸
sizes := []uint{16, 32, 64, 128} // 可根据需求添加更多尺寸
var icoImages []image.Image
// 4. 缩放图像到每个目标尺寸并收集
for _, size := range sizes {
// 使用Lanczos3算法缩放高质量
resized := resize.Resize(size, size, img, resize.Lanczos3)
icoImages = append(icoImages, resized)
}
// 5. 编码为ICO并写入文件关键修改使用icox.Encode
icoFile, err := os.Create(outputPath)
if err != nil {
panic("无法创建ICO文件: " + err.Error())
}
defer icoFile.Close()
// icox.Encode直接支持多尺寸切片[]image.Image
if err := icox.Encode(icoFile, icoImages); err != nil {
panic("ICO编码失败: " + err.Error())
}
//// 1. 读取PNG文件
//inputPath := "manifest/images/logo.png" // 输入PNG路径
//outputPath := "manifest/images/favicon.ico" // 输出ICO路径
//
//pngFile, err := os.Open(inputPath)
//if err != nil {
// panic("无法打开PNG文件: " + err.Error())
//}
//defer pngFile.Close()
//
//// 2. 解码PNG为image.Image对象
//img, _, err := image.Decode(pngFile)
//if err != nil {
// panic("PNG解码失败: " + err.Error())
//}
//
//// 3. 定义ICO需要包含的尺寸常见尺寸
//sizes := []uint{16, 32, 64, 128} // 可根据需求添加更多尺寸
//var icoImages []image.Image
//
//// 4. 缩放图像到每个目标尺寸并收集
//for _, size := range sizes {
// // 使用Lanczos3算法缩放高质量
// resized := resize.Resize(size, size, img, resize.Lanczos3)
// icoImages = append(icoImages, resized)
//}
//
//// 5. 编码为ICO并写入文件关键修改使用icox.Encode
//icoFile, err := os.Create(outputPath)
//if err != nil {
// panic("无法创建ICO文件: " + err.Error())
//}
//defer icoFile.Close()
//
//// icox.Encode直接支持多尺寸切片[]image.Image
//if err := icox.Encode(icoFile, icoImages); err != nil {
// panic("ICO编码失败: " + err.Error())
//}
}