Reputation: 3923
I have this simple script - which seems to be how every search I find tells me to extract an icon for use:
$Format = [System.Drawing.Imaging.ImageFormat]::Icon
$Source = 'C:\Windows\System32\DeviceProperties.exe'
[System.Drawing.Icon]::ExtractAssociatedIcon($Source).ToBitmap().Save("c:\temp\extracted.ico",$Format)
Problem being that the resulting file is not a Windows icon file. As evidenced when you try to apply this icon to a shortcut or similar I receive this Windows error:
The file C:\Temp\extracted contains no icons
Choose an icon from the list or specify a diferent file
I'm assuming here it's because the result is a bitmap rather than an icon format.
The question is - how to convert this to a proper icon file ready for use?
Upvotes: 4
Views: 7059
Reputation: 103
The exported file: c:\temp\extracted.ico
is a png file, not a ico file. I haven't found a way to convert this with powershell to ico format, either. But gimp e.g. can do this job.
Do the following:
This will convert the file format from png to ico and you won't lose transparency.
Upvotes: 3
Reputation: 1216
I have encountered the same limitation a long time ago and gave up, I believe.
However, this one looks promising - a pre-made module to export, and it supposedly supports .ico format.
https://gallery.technet.microsoft.com/scriptcenter/Export-Icon-from-DLL-and-9d309047
I didn't test it, so I hope they didn't just rename the .bmp to .ico (because then it would probably not work either).
Upvotes: 2
Reputation: 459
An icon file is a file that contains many bitmap images (I think at some point they were 7). When trying to create an ico in GIMP for example you must put 7 bitmaps into it, each in it's own layer. I assume you should use something different than ToBitmap.
PS: I don't have access to a Windows machine to actually try your powershell script/command and I don't have enough reputation to just comment.
Upvotes: 0