Repository navigation
Expand file tree
/
Copy pathmake_icon.ps1
More file actions
62 lines (50 loc) · 1.67 KB
/
Copy pathmake_icon.ps1
File metadata and controls
62 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Add-Type -AssemblyName System.Drawing
$pngPath = Join-Path $PSScriptRoot "resources\icons\app.png"
$icoPath = Join-Path $PSScriptRoot "resources\icons\app.ico"
$sizes = @(256, 128, 64, 48, 32, 16)
$pngStreams = @()
foreach ($size in $sizes) {
$src = [System.Drawing.Image]::FromFile($pngPath)
$bmp = New-Object System.Drawing.Bitmap($size, $size)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
$g.Clear([System.Drawing.Color]::Transparent)
$g.DrawImage($src, 0, 0, $size, $size)
$g.Dispose()
$src.Dispose()
$ms = New-Object System.IO.MemoryStream
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$bmp.Dispose()
$pngStreams += $ms
}
$icoStream = [System.IO.File]::Create($icoPath)
$bw = New-Object System.IO.BinaryWriter($icoStream)
$count = $sizes.Count
$bw.Write([uint16]0)
$bw.Write([uint16]1)
$bw.Write([uint16]$count)
$headerSize = 6 + $count * 16
$offset = $headerSize
foreach ($i in 0..($count - 1)) {
$size = $sizes[$i]
$pngBytes = $pngStreams[$i].ToArray()
$byteCount = $pngBytes.Length
$displaySize = if ($size -ge 256) { 0 } else { $size }
$bw.Write([byte]$displaySize)
$bw.Write([byte]$displaySize)
$bw.Write([byte]0)
$bw.Write([byte]0)
$bw.Write([uint16]1)
$bw.Write([uint16]32)
$bw.Write([uint32]$byteCount)
$bw.Write([uint32]$offset)
$offset += $byteCount
}
foreach ($ms in $pngStreams) {
$bw.Write($ms.ToArray())
$ms.Dispose()
}
$bw.Close()
$icoStream.Close()
Write-Host " [OK] Icon saved to: $icoPath"