I use the PowerGUI editor to convert a ps1 file to an exe file. Reason is that I dont want people to see my source code. The script includes a own little GUI with a picture on it. My problem is that after converting the script to an exe file the picture will only be shown when it exists on a specific path. If I delete or move the picture from that path it wont be shown when starting the exe.
我使用PowerGUI编辑器将ps1文件转换为exe文件。原因是我不希望别人看到我的源代码。该脚本包含一个自带的小GUI,上面有图片。我的问题是,在将脚本转换为exe文件后,只有当它存在于特定路径上时才会显示图片。如果我从该路径中删除或移动图片,则在启动exe时不会显示。
How can I include the picture to the exe? I want to have only one file in the end ...
如何将图片包含在exe中?我想最后只有一个档案......
1 个解决方案
#1
1
One way you could do this is by converting your image into a Base 64 String
, using the following:
一种方法是使用以下方法将图像转换为Base 64 String:
[convert]::ToBase64String((get-content C:\YourPicture.jpg -encoding byte)) > C:\YourString.txt
With the string that is produced in the text file "C:\YourString.txt" you can copy and paste it into your code and load it into a picture object on the form like so:
使用在文本文件“C:\ YourString.txt”中生成的字符串,您可以将其复制并粘贴到代码中并将其加载到表单上的图片对象中,如下所示:
$logo.Image = [System.Convert]::FromBase64String('
iVBORw0KGgoAAAANSUhEUgAAAfQAAACMCAYAAACK0FuSAAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAXEQAAFxEByibzPwAAAAd0SU1FB98DFA8VLc5RQx4AANRpSURBVHhe7J0FmBTX0oZ7F1jc3d3d
nU+dOtXw4MGDZfft25fmyJEjPu+//76Xqzke8pCHPOQhD3lIQGxxcGSapvHdd9+FF3hHEdjGFHgn
....... Many more lines of string .......
OqelFQzDMAzD/CZoztADbUwhUm0JERoXCNfEQYhyPAQryiBIUQSBiiTwl1sb3skwDMMwzG+KWLVe
jTEBH6U7JvJ0CJQXoaGPQMWBm5W+Va27k14MwzDMfwCA/wfUstOLO+nBIAAAAABJRU5Jggg==')
Do this will mean that your image is stored within the code already and doesn't need to be loaded from somewhere.
这样做意味着您的图像已经存储在代码中,并且不需要从某个地方加载。
Note: Make sure that the pictures size on disk is the smallest you can get it as producing the string can take sometime and could turn out thousands of lines long. So I would recommend that you only use a pic that is less that 75 Kilobytes in size. You could do it with larger one but this will take a long time to process.
注意:确保磁盘上的图片大小是最小的,因为生成字符串可能需要一段时间,并且可能会长达数千行。所以我建议你只使用一个小于75千字节的图片。你可以用更大的一个来做,但这需要很长时间来处理。
#1
1
One way you could do this is by converting your image into a Base 64 String
, using the following:
一种方法是使用以下方法将图像转换为Base 64 String:
[convert]::ToBase64String((get-content C:\YourPicture.jpg -encoding byte)) > C:\YourString.txt
With the string that is produced in the text file "C:\YourString.txt" you can copy and paste it into your code and load it into a picture object on the form like so:
使用在文本文件“C:\ YourString.txt”中生成的字符串,您可以将其复制并粘贴到代码中并将其加载到表单上的图片对象中,如下所示:
$logo.Image = [System.Convert]::FromBase64String('
iVBORw0KGgoAAAANSUhEUgAAAfQAAACMCAYAAACK0FuSAAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAXEQAAFxEByibzPwAAAAd0SU1FB98DFA8VLc5RQx4AANRpSURBVHhe7J0FmBTX0oZ7F1jc3d3d
nU+dOtXw4MGDZfft25fmyJEjPu+//76Xqzke8pCHPOQhD3lIQGxxcGSapvHdd9+FF3hHEdjGFHgn
....... Many more lines of string .......
OqelFQzDMAzD/CZoztADbUwhUm0JERoXCNfEQYhyPAQryiBIUQSBiiTwl1sb3skwDMMwzG+KWLVe
jTEBH6U7JvJ0CJQXoaGPQMWBm5W+Va27k14MwzDMfwCA/wfUstOLO+nBIAAAAABJRU5Jggg==')
Do this will mean that your image is stored within the code already and doesn't need to be loaded from somewhere.
这样做意味着您的图像已经存储在代码中,并且不需要从某个地方加载。
Note: Make sure that the pictures size on disk is the smallest you can get it as producing the string can take sometime and could turn out thousands of lines long. So I would recommend that you only use a pic that is less that 75 Kilobytes in size. You could do it with larger one but this will take a long time to process.
注意:确保磁盘上的图片大小是最小的,因为生成字符串可能需要一段时间,并且可能会长达数千行。所以我建议你只使用一个小于75千字节的图片。你可以用更大的一个来做,但这需要很长时间来处理。