2015-02-22 18:37:39 +01:00
|
|
|
<Query Kind="Statements">
|
|
|
|
<Namespace>System.Drawing</Namespace>
|
|
|
|
<Namespace>System.Drawing.Imaging</Namespace>
|
|
|
|
</Query>
|
|
|
|
|
2016-12-14 01:27:00 +01:00
|
|
|
string inputDirectory = @"resources\logo";
|
|
|
|
string outputPath = Path.Combine(inputDirectory, "icon.ico");
|
|
|
|
int[] imageSizes = new int[] { 256, 128, 64, 40, 32, 16, 8, 4 };
|
2015-02-22 18:37:39 +01:00
|
|
|
using (FileStream fs = new FileStream(outputPath, FileMode.Create)) {
|
|
|
|
BinaryWriter bw = new BinaryWriter(fs);
|
|
|
|
bw.Write((short)0);
|
|
|
|
bw.Write((short)1);
|
2016-12-14 01:27:00 +01:00
|
|
|
bw.Write((short)imageSizes.Length);
|
2015-02-22 18:37:39 +01:00
|
|
|
|
2016-12-14 01:27:00 +01:00
|
|
|
int dataStartOffset = 6 + (imageSizes.Length * 16);
|
2015-02-22 18:37:39 +01:00
|
|
|
|
|
|
|
using (MemoryStream dataStream = new MemoryStream()) {
|
2016-12-14 01:27:00 +01:00
|
|
|
foreach (int size in imageSizes) {
|
2015-02-22 18:37:39 +01:00
|
|
|
bw.Write((byte)(size == 256 ? 0 : size));
|
|
|
|
bw.Write((byte)(size == 256 ? 0 : size));
|
|
|
|
bw.Write((byte)0);
|
|
|
|
bw.Write((byte)0);
|
|
|
|
bw.Write((short)0);
|
|
|
|
bw.Write((short)32);
|
|
|
|
|
|
|
|
int dataOffset = (int)dataStream.Position;
|
|
|
|
int dataLength;
|
|
|
|
|
|
|
|
string inputImagePath = Path.Combine(inputDirectory, "icon_x" + size + ".png");
|
|
|
|
using (Image image = Image.FromFile(inputImagePath))
|
|
|
|
image.Save(dataStream, ImageFormat.Png);
|
|
|
|
|
|
|
|
dataLength = (int)dataStream.Position - dataOffset;
|
|
|
|
dataOffset += dataStartOffset;
|
|
|
|
|
|
|
|
bw.Write(dataLength);
|
|
|
|
bw.Write(dataOffset);
|
|
|
|
}
|
|
|
|
bw.Write(dataStream.ToArray());
|
|
|
|
}
|
2016-12-14 01:27:00 +01:00
|
|
|
}
|