0

我想不出解决办法。这是我的代码:

   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)

我能做些什么来消除错误?

4

1 回答 1

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
于 2013-02-01T22:04:51.793 回答