Results 1 to 10 of 10

Thread: ScreenShot , Custom Save In Timer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    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

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Re: ScreenShot , Custom Save In Timer

    Quote Originally Posted by chris128 View Post
    So have you actually searched for (or attempted) any of these things yet?
    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.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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:
    1. Dim SomeString As String = "there"
    2. MessageBox.Show("Hello " & SomeString)
    That would output "Hello there" in a messagebox.
    Is that the part you are struggling with?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    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

    A generic error occurred in GDI+.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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):
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    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")
    thank you works perfectly. How would i go about creating a folder and saving this into a folder based on the date?

  8. #8

    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")

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: ScreenShot , Custom Save In Timer

    Ideally you would replace FolderPath & "\SLaptop etc etc with IO.Path.Combine(FolderPath, "SLaptop etc etc")
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10

    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..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width