C++通过SHGetFileInfo拿到的图标是HICON类型。
WPF要显示只能用Image控件,设置Source源,需要HICON转ImageSource
//IntPtr pIconData 通过HICON强转
private ImageSource IconDataToImageSource(IntPtr pIconData)
{
ImageSource imageSoure = null;
System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(pIconData);
//拿到的是大图标
Int32Rect rect = new Int32Rect(0, 0, 32, 32);
imageSoure = Imaging.CreateBitmapSourceFromHIcon(pIconData, rect, BitmapSizeOptions.FromEmptyOptions());
return imageSoure;
}