2012-01-09 16 views
0

visual basic expressを使用してVisual Basic.netの以下のコードでこのエラーを解決するにはどうすればよいですか? サポートされていない例外は、3回のループの後に処理されませんでした。 "PictureBox1.Image.Save(dtmTestX、System.Drawing.Imaging.ImageFormat.Jpeg)"visualbasic.netでの一般的なエラー

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 

    Dim dtmTest As Date 
    dtmTest = TimeValue(Now) 
    Dim bounds As Rectangle 
    Dim screenshot As System.Drawing.Bitmap 
    Dim graph As Graphics 
    Dim dtmTestSaveLocation As String 
    dtmTestSaveLocation = "D:\test" + dtmTest + ".jpg" 

    bounds = Screen.PrimaryScreen.Bounds 
    screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) 
    graph = Graphics.FromImage(screenshot) 
    graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy) 
    PictureBox1.Image = screenshot 

    PictureBox1.Image.Save(dtmTestSaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg) 
End Sub 
+0

正確には、表示されるエラーメッセージは何ですか? – CedX

+1

タグが付け直されました。これはVBAではありません。 – HardCode

+0

ファイル名には、DateTimeから文字列への変換までの ":"文字が含まれます。これはファイル名に有効な文字ではありません。 –

答えて

0

あなたが行を変更する必要があります:

PictureBox1.Image.Save(dtmTestX, System.Drawing.Imaging.ImageFormat.Jpeg) 

へ:

PictureBox1.Image.Save(dtmTestSaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg) 

また、実際にグラフィックス要素をタグを使って埋め込んで、適切に廃棄されるようにする必要があります。

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    Try 
     Dim dtmTest As Date 
     Dim bounds As Rectangle 
     Dim dtmTestSaveLocation As String 

     dtmTest = TimeValue(Now) 
     dtmTestSaveLocation = "D:\test" & dtmTest.ToShortTimeString.Replace(":", "_") & ".jpg" 

     bounds = Screen.PrimaryScreen.Bounds 
     Using screenshot As New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) 
      Using graph As Graphics = Graphics.FromImage(screenshot) 
       graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy) 
       PictureBox1.Image = screenshot 
       screenshot.Save() 
       PictureBox1.Image.Save(dtmTestSaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg) 
      End Using 
     End Using 
    Catch theException As Exception 
     Console.WriteLine(theException.ToString) 
     ' Note: In production code, you would want to do something useful with the exception 
     ' here, such as showing it to the user in a messagebox or writing it to a log 
    End Try 
End Sub 
+0

同じエラー:サポートされていない例外が処理されていません – user101579

+0

質問を編集して完全な例外テキストとスタックトレースを含めることはできますか?この情報は、try/catchブロックにテキストをラップし、例外のtostringメソッドを使用してすべてをコンソールに書き込むことで取得できます。必要に応じて、このコードを表示するための回答を更新することができます。 –

+0

PictureBox1.Image.Save(dtmTestSaveLocation、System.Drawing.Imaging.ImageFormat.Jpeg) - NotSupportedExceptionが未処理です - 指定されたパスの形式はサポートされていません。 – user101579

関連する問題