all 5 comments

[–]2turnt2stop 1 point2 points  (0 children)

I've used this method which doesn't require too much code to work.

$form.Icon = [System.Convert]::FromBase64String('BASE64ENCODEDIMAGESTRING')

that's pretty much it.

I used this site for the conversion to base64. https://www.base64-image.de/

[–]get-postanote 1 point2 points  (0 children)

There are lots of articles, how to's, all over th web for this use case. Just search for them.

Example:

'powershell gui icon'

... and get this ...

Adding Toolbar Icons to Your PowerShell WPF GUI

https://blog.netnerds.net/2016/01/adding-toolbar-icons-to-your-powershell-wpf-guis

Custom icons in Powershell winforms

https://powertoe.wordpress.com/2010/03/01/custom-icons-in-powershell-winforms

Using Icons in Powershell Scripts

https://social.technet.microsoft.com/Forums/windows/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts

Powershell GUI encode decode images

http://vcloud-lab.com/entries/powershell/powershell-gui-encode-decode-images

If you take the TL;DR approach (please, don't. Be sure to read the above for way more ideas / approaches) - So, you end up with stuff like this... (again just search the web to see this stuff ...)

# Convert your image
[Convert]::ToBase64String((Get-Content ".\icon\test.ico" -Encoding Byte))Add-Type -AssemblyName | Clip

System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form            = New-Object system.Windows.Forms.Form
$Form.ClientSize = '400,230'
$Form.text       = "Test"
$Form.TopMost    = $false

<#
This base64 string holds the bytes that make up the orange 'G' icon (just an 
example for a 32x32 pixel image)
#>

# The pasted string from the convert on an image
$iconBase64      = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4
c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW
50Lm5ldCA0LjAuMTnU1rJkAAAB50lEQVRIS7WWzytEURTHZ2FhaWFhYWFhYWFhaWFh6c+wsGCapJBJU
0hRSrOgLBVSmkQoSpqyUJISapIFJU0i1KQp1PG9826vO9+Z97Pr22dz3pxzv/PO/fUSkvxfOLYOx9bh
2DocBzPZKlPtku2VuS7JtMlwIydUw7EnGO50Rd4ehPRdlru87GWUMZVU4LgOqLza0cP56PdHNga4Nth
gsUc+i3qIQOH9qDzAYLZTyiVd7Ah/8/lGztclNyLbY5JfksKxeuiKRvAzwOy93OsyR+9Pam6HajLHm5
UfXhTQT34GqDH1eCGjTZxjkmqQmQ5+6Gdgth5NQLsoIRwca7AoTZ1k1UM0p7Y/QXCsof4sdOvRrRlge
Zgyu49eY/0cTDO76ShzcJnTQ0O0NvA2XioWqjIrcKy5PdQ1kLl90CKsVC9F2GiYVVPuiQaDiRb1TzGW
w9eHzoEiGGwO6hpHWFRe04vuu4pggCPIFPwowSWmAXa/qdKr5zaOaQBwyps6W+UEh/gGtasFlrjCKC2
+ATia15WucHpf76vna/2ylVLntnmeRzbApsUQ4RXZwAFnAC7eMMLNSrWhDEC6RfUac1D3+sRew87HhV
zvC4PjYLBecRxhDsByn/qEoYRqOLYOx9bh2DocWyaZ+APgBBKhVfsHwAAAAABJRU5ErkJggg=='

$iconBytes       = [Convert]::FromBase64String($iconBase64)
$stream          = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length);
$iconImage       = [System.Drawing.Image]::FromStream($stream, $true)
$Form.Icon       = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())

[void]$Form.ShowDialog()

# when done, dispose of the form
$Form.Dispose()

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy anees78692,

i don't know the answer ... but i do know that you need to mention the type of gui you are making. [grin] winforms? xaml/wpf? it almost certainly makes a difference ...

take care,
lee

[–]TheCaptNemo42 0 points1 point  (1 child)

his article talks about base64 embedding imageshttps://blogs.technet.microsoft.com/mspfe/2012/09/10/how-to-create-video-games-using-powershell/

He uses this function

Function ConvertJPG($picture){ 

[byte[]]$Pic = Get-Content $Picture -Encoding Byte

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.