2017-07-30 75 views
3

我已經開始一個新的應用程序,並且每30秒它會將圖片保存到臨時目錄,但我需要保存每個照片用不同的名稱,如MDAL1Image1.jpg,MDAL1Image2.jpg等,但我得到這個錯誤從字符串「C: Mediamemebuilderpro MDAL1Imag」轉換爲輸入'Double'無效。「

{"Conversion from string "C:\Mediamemebuilderpro\MDAL1Imag" to type 'Double' is not valid."} 

這是我的錯誤

PB1.Save("C:\Mediamemebuilderpro\" + "MDAL1Image" + nametosave + ".jpg", System.Drawing.Imaging.ImageFormat.Bmp) 
    timetosavetemp = 0 

這是代碼我得到錯誤的行

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick 
    timetosavetemp = timetosavetemp + 1 
    If timetosavetemp >= 30 Then 
     Dim nametosave = 1 
     nametosave = nametosave + 1 
     Dim PB1 As New Bitmap(PictureBox1.Image) 

     PB1.Save("C:\Mediamemebuilderpro\" + "MDAL1Image" + nametosave + ".jpg", System.Drawing.Imaging.ImageFormat.Bmp) 
     timetosavetemp = 0 

    End If 
End Sub 
+0

[在VB.NET中加入和加入字符串的區別](https://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in- vb-net) –

回答

3

使用String.Format構造文件名,根據需要更改段。

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) 

當使用... "MDAL1Image" + nametosave + ...它試圖在nametosave這是一個雙,和"MDAL1Image"執行二進制運算,它是一個字符串。它無法將該字符串解釋爲有效的雙精度值。

+0

坦克,解決了這個問題,但我需要它爲每張照片分配新名稱,但它只保存一張照片。 – ines

+1

'ticksave'的值不會在記號間記住。你可能想要得到一個日期時間戳,並用它來代替。這可能會幫助你:https://stackoverflow.com/questions/14294156/how-to-get-current-timestamp –

相關問題