我无法弄清楚解决方案。这是我的代码:
Dim wbRect As Rectangle = WebBrowser1.ClientRectangle
Dim wbBm As New Bitmap(WebBrowser1.ClientRectangle.Width, WebBrowser1.ClientRectangle.Height)
Dim gwb As Graphics = Graphics.FromImage(wbBm)
gwb.CopyFromScreen(WebBrowser1.PointToScreen(New Point(14, 31)),
New Point(0, 0),
New Size(PictureBox1.Width, PictureBox1.Height))
wbBm.Save("c:\temp1.bmp")
PictureBox1.ImageLocation = "c:\temp1.bmp"
PictureBox1.BringToFront()
Dim bm As New Bitmap("c:\img1.bmp") //here appears an error - Parameter is not valid
Dim rect As New Rectangle(0, 0, bm.Width, bm.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = bm.LockBits(rect, _
System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
我该怎么做才能删除错误?
答案 0 :(得分:0)
如果文件不存在,您将收到此错误。在尝试打开它之前,请检查以确保img1.bmp存在:
Dim fn As String = "c:\img1.bmp"
If File.Exists(fn)
Dim bm As New Bitmap(fn) ''here appears an error - Parameter is not valid
Dim rect As New Rectangle(0, 0, bm.Width, bm.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = bm.LockBits(rect, _
System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
End If