我正在尝试将 jpg 用于 Powershell 表单中的按钮图像。我试过这段代码:
#Add Image to Button
$image = New-Object System.Windows.Controls.Image
$image.Source = "C:\users\Administrator\Desktop\Avengers.jpg"
$image.Stretch = 'Fill'
$button.Content = $image
发件人:http://learn-powershell.net/2012/10/01/powershell-and-wpf-buttons/
脚本抛出错误: 找不到类型 [System.Controls.Image]:确保已加载包含此类型的程序集。
我尝试使用脚本中的另一个程序集来解决这个问题: [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
我被版本、文化和 PublicKeyToken 困住了(我在 Powershell Studio 中启动脚本,但在 Notepad++ 中完成)。我怎样才能最好地获取这些信息?
谢谢。
最佳答案
您选择了一种很酷的语言来进行 .Net 开发!!不过这有点困难,因为几乎没有文档可以提供帮助。
尝试使用 System.Drawing.Image,而不是使用 System.Controls.Image:
Add-Type -Assembly System.Drawing
$image = [System.Drawing.Image]::FromFile("C:\users\Administrator\Desktop\Avengers.jpg")
$button.Image = $image
关于image - Powershell 按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27242315/