怎么通过unity读取外部exe文件的图标,用System.Drawing.Icon不可以
[DllImport("shell32.DLL", EntryPoint = "ExtractAssociatedIcon")]
private static extern int ExtractAssociatedIconA(int hInst, string lpIconPath, ref int lpiIcon); //声明函数
static System.IntPtr thisHandle;
public Image GetIcon(string path)
{
int RefInt = 0;
thisHandle = new IntPtr(ExtractAssociatedIconA(0, path, ref RefInt));
Image image = System.Drawing.Icon.FromHandle(thisHandle).ToBitmap();
return image;
}
这个项目里有获取其他文件ico图标的例子。
https://gitee.com/apull/EXEStart
你把这个dll导入工程就行System.Drawing
给你说个大概 具体差不多
打开Unity场景,新建脚本,名称自拟。在脚本里输入代码,使按下键盘上的O键就打开指定路径下的应用程序(应用程序必须存在)。创建空物体,把脚本给空物体。点击播放按钮测试,按键盘上的O键,打开指定应用程序。