我嘗試每隔30秒將臨時目錄保存爲臨時目錄,但每個目錄只保存一次,給我一個錯誤 這是我的錯誤我嘗試每隔30秒將臨時目錄保存爲臨時目錄,但每次只能保存一次
A generic error occurred in GDI+.
堆棧跟蹤
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
在System.Drawing.Image.Save(字符串文件名,格式的imageformat) 在WindowsApplication1.Form1.savetempfoto()在Form1中.vb:line 372
而行的錯誤是
PB1.Save(path, System.Drawing.Imaging.ImageFormat.Bmp)
這是我的代碼
Public Function temdirx()
My.Computer.FileSystem.CreateDirectory(tempdir)
End Function
Public Function timesavetemp()
Timer2.Start()
End Function
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
timetosavetemp = timetosavetemp + 1
If timetosavetemp >= 30 Then
savetempfoto()
timetosavetemp = 0
End If
End Sub
Public Function savetempfoto()
Dim PB1 As New Bitmap(PictureBox1.Image)
'Dim frame As Long 'individual frames
'Dim strings As String
'strings = frame
'Dim path As String = String.Format("C:\Mediamemebuilderpro\MDAL1Image{0}.jpg", nametosave)
'PB1.Save(path, System.Drawing.Imaging.ImageFormat.Bmp)
'PB1.Save("C:\Mediamemebuilderpro\MDAL1Image" & strings & ".jpg", System.Drawing.Imaging.ImageFormat.Bmp)
'frame += 1
Dim filename As String = "MDAL1Image" 'Change as needed
Dim path As String = String.Format("C:\Mediamemebuilderpro\{0}{1}.jpg", filename, nametosave)
PB1.Save(path, System.Drawing.Imaging.ImageFormat.Bmp)
timetosavetemp = 0
End Function
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
For Each file As String In IO.Directory.GetFiles("C:\Mediamemebuilderpro", "*.*")
ListBox1.Items.Add(file)
Next
End Sub
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
ListBox1.Items.Clear()
End Sub
顯示如何創建計時器。將時間設置爲30分鐘。至於錯誤。請檢查以確保保存位置存在,並且您有權修改它。在標題中你也有30秒的時間,但在問題的主體中有30分鐘。您需要澄清 – Nkosi
Save()方法會對該文件進行鎖定。所以它會第二次失敗,你不能覆蓋一個鎖定的文件。漂亮的基本錯誤,你忘了處理位圖。使用'Using'語句。 –
@HansPassant您好坦克的重播可以請給我一個例子如何做? – ines