PNG抠图工具
纯色背景才可剔除;
批量导出png;
修改config.txt
#剔除的背景色
bkgcolor:0,254,0
#源文件夹
srcPath:./src
#目标文件夹
distPath:./new
运行PngTool.exe
主要方法:将颜色和bkgcolor相同的像素,alpha值改0;
用惯了c#的库真越觉得c#真是个优雅的语言,写起来比cpp简单太多了;
public static void SetTransparent(string path, Color bkgCol, string distPath)
{
Bitmap bmp = new Bitmap(path);
for (int h = 0; h < bmp.Height; h++)
{
for (int w = 0; w < bmp.Width; w++)
{
Color color = bmp.GetPixel(w, h);
if (color.R == bkgCol.R && color.G == bkgCol.G && color.B == bkgCol.B)
{
color = Color.Transparent;
bmp.SetPixel(w, h, color);
}
}
}
string savePath = path.Split('\\').Last<string>();
bmp.Save(distPath + "/" + savePath);
bmp.Dispose();
}
下载地址:https://files.cnblogs.com/files/blogs/703006/pngtool.7z?t=1654761000
Life is too short for so much sorrow.
本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0 许可协议。转载请注明来自 小紫苏!