ScreenShot , Custom Save In Timer
I have been looking around and failed to find something like this. Im looking for code that will take a screen shot of the screen every X amount of seconds and save it with a filename of like "SSLaptop Todays Date & Time"
Is there code for this ?
thanks in advance
Re: ScreenShot , Custom Save In Timer
No there is not any code that takes a screenshot every X seconds and saves it with that file name... however you can be pretty sure that there are a lot of examples of how to do something every X seconds (timer), how to take a screenshot (windows APIs) and how to save the result of that API to a file.
So have you actually searched for (or attempted) any of these things yet?
Re: ScreenShot , Custom Save In Timer
Quote:
Originally Posted by
chris128
So have you actually searched for (or attempted) any of these things yet?
Quote:
I have been looking around and failed to find something like this
Yes. I have looked round i found code , but they dont save custom filenames with strings inside them , the x amount of seconds was taken care of with a timer.
Re: ScreenShot , Custom Save In Timer
So you found examples that dont save "custom filenames" - as there is no such thing as a default file name I am a little puzzled how you can save a file without using a custom filename...
If you simply want to use a variable within a string you can just use the & operator to append the vairable to the string. For example:
vb Code:
Dim SomeString As String = "there"
MessageBox.Show("Hello " & SomeString)
That would output "Hello there" in a messagebox.
Is that the part you are struggling with?
Re: ScreenShot , Custom Save In Timer
Code:
Dim b as Bitmap
b = New Bitmap(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height))
Dim sfd As New SaveFileDialog()
sfd.Filter = "(*.bmp)|*.bmp"
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
b.Save(sfd.FileName & Date.Now.Date)
End If
This was the code im using but it using a save dialog box so i changed it to
Code:
Dim b As Bitmap
b = New Bitmap(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height))
b.Save("SSLaptop" & Date.Now.Date)
And its this line that it kicks up about
Code:
b.Save("SSLaptop" & Date.Now.Date)
Error
Quote:
A generic error occurred in GDI+.
Re: ScreenShot , Custom Save In Timer
Well thats probably because Date.Now.Date returns a Date object and when converted to a String it looks something like this: 06/08/2009 - so you are trying to save a file with a name that contains the forward slash character ( / ) and that is not allowed in file names. Thats not a VB.NET rule, thats a rule of the file system (or Windows).
So you could use something like the String.Replace method to replace the forward slashes with hyphens (which ARE allowed in file names):
Re: ScreenShot , Custom Save In Timer
Code:
Dim b As Bitmap
b = New Bitmap(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height))
Dim LDate As String = Date.Now.Date
Dim Ldate2 As String = LDate.Replace("/", "-")
Dim Ltime As String = DateTime.Now.ToLongTimeString
Dim Ltime2 As String = Ltime.Replace(":", "-")
MessageBox.Show("SSLaptop" & " " & Ldate2 & " " & Ltime2 & ".jpg")
b.Save("SSLaptop" & " " & Ldate2 & " " & Ltime2 & ".jpg")
:D thank you works perfectly. How would i go about creating a folder and saving this into a folder based on the date?
Re: ScreenShot , Custom Save In Timer
Dim FolderPath As String = "C:\NewFolder"
Directory.Create(FolderPath)
Then when you save the file
b.Save(FolderPath & "\SLaptop " & Ldate2 & " " & Ltime2 & ".jpg")
Re: ScreenShot , Custom Save In Timer
Ideally you would replace FolderPath & "\SLaptop etc etc with IO.Path.Combine(FolderPath, "SLaptop etc etc") :)
Re: ScreenShot , Custom Save In Timer
Well blah!!! :P
I actually didn't know that, thanks chris, that'll be very helpful in the future for me..