1. dll 生成
visual studio 新建 c# 桌面项目
声明 Program 类 提供 extractIcon 接口 返回 base64 编码的图片信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace dotDesc
{
public class Program
{
public String extractIcon(String path)
{
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(path);
System.Drawing.Bitmap bitmap = icon.ToBitmap();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
return Convert.ToBase64String(memoryStream.ToArray());
}
}
}
设置输出方式为类库 重新编译后 bin 目录可以找到对应 dll 文件
2. python 引用
依赖
pip install pythonnet
import clr
clr.AddReference("./dotDesc")
from dotDesc import Program
p = Program()
icon = p.extractIcon("D:\\dev_tools\\node\\node.exe")
展示如下:
|