系统图标-测试

This commit is contained in:
liufei
2021-12-23 17:58:06 +08:00
parent 09d3a520b4
commit e3a85e42fa
5 changed files with 370 additions and 1 deletions

View File

@@ -72,6 +72,22 @@ namespace GeekDesk.Util
ico = Icon.FromHandle(ip);
}
IntPtr hIcon2 = IntPtr.Zero;
//TODO
for (int i=0; i<=1000; i++)
{
try
{
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", i, hIcon2);
Bitmap bmp2 = ico.ToBitmap();
bmp2.Save("d:\\test\\" + i + ".png");
} catch
{
}
}
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", 16, hIcon2);
Bitmap bmp = ico.ToBitmap();
MemoryStream strm = new MemoryStream();
@@ -80,7 +96,7 @@ namespace GeekDesk.Util
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 75L);
EncoderParameters myEncoderParameters = new EncoderParameters(1);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp.Save("d:\\test.png");
bmp.Save(strm, myImageCodecInfo, myEncoderParameters);
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();

34
Util/SystemIcon.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Util
{
public class SystemIcon
{
[DllImport("Shell32.dll")]
public static extern int ExtractIcon(IntPtr h, string strx, int ii);
public static Icon MyExtractIcon(string FileName, int iIndex, IntPtr h)
{
try
{
IntPtr hIcon = (IntPtr)ExtractIcon(h, FileName, iIndex);
if (!hIcon.Equals(null))
{
Icon icon = Icon.FromHandle(hIcon);
return icon;
}
}
catch (Exception ex)
{
}
return null;
}
}
}