尝试将图像从 URL 下载到内存中。在响应流上出现错误。
使用“1”参数调用“FromStream”的异常:“'null' 的值对 'stream' 无效。”
Function Download-Image {
$req = [System.Net.WebRequest]::Create
("http://www.wired.com/images_blogs/business/2012/12/google.jpg")
$response = $req.GetResponse()
$ResponseStream = $Response.GetResponseStream()
[System.IO.Stream]$stream = $ResponseStream
#$response.close()
}
[byte[]]$image = Download-Image
Add-Type -AssemblyName System.Windows.Forms
$img = [System.Drawing.Image]::FromStream([System.IO.MemoryStream]$image)
[System.Windows.Forms.Application]::EnableVisualStyles()
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Width
$pictureBox.Height = $img.Height
$pictureBox.Image = $img
$form = new-object Windows.Forms.Form
$form.Width = $img.Width
$form.Height = $img.Height
$form.AutoSize = $True
$form.AutoSizeMode = "GrowAndShrink"
$form.Icon = $icon
$form.controls.add($pictureBox)
$form.Add_Shown( { $form.Activate() } )
$form.ShowDialog()