R
ray230
Guest
Ok got it working but how do i save?
What format?
Tryed .wmv But didn't play neither .gif?
help please X Zero
How did you get it to work?
Give me your code that you used please.
Thank you.
Ok got it working but how do i save?
What format?
Tryed .wmv But didn't play neither .gif?
help please X Zero
Public Class ScreenRecorder
Private Shared tempDir As String = My.Computer.FileSystem.SpecialDirectories.Temp & "\snapshot\"
Private Shared snap As New System.Threading.Thread(AddressOf Snapshot)
Private Shared _Bounds As System.Drawing.Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds
Public Shared Property Bounds() As System.Drawing.Rectangle
Get
Return _Bounds
End Get
Set(ByVal value As System.Drawing.Rectangle)
_Bounds = value
End Set
End Property
Private Shared Sub Snapshot()
If Not My.Computer.FileSystem.DirectoryExists(tempDir) Then _
My.Computer.FileSystem.CreateDirectory(tempDir)
Dim Co As Integer = 0
Do
Co += 1
System.Threading.Thread.Sleep(50)
Dim X As New System.Drawing.Bitmap(_Bounds.Width, _Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Using G = System.Drawing.Graphics.FromImage(X)
G.CopyFromScreen(_Bounds.Location, New System.Drawing.Point(), _Bounds.Size)
Dim CurBounds As New System.Drawing.Rectangle(System.Windows.Forms.Cursor.Position - Bounds.Location, System.Windows.Forms.Cursor.Current.Size)
Forms.Cursors.Default.Draw(G, CurBounds)
End Using
Dim FS As New IO.FileStream(tempDir & FormatString(Co.ToString, 5, "0"c) & ".png", IO.FileMode.OpenOrCreate)
X.Save(FS, System.Drawing.Imaging.ImageFormat.Png)
X.Dispose()
FS.Close()
Loop
End Sub
Public Shared Sub ClearRecording()
If My.Computer.FileSystem.DirectoryExists(tempDir) Then _
My.Computer.FileSystem.DeleteDirectory(tempDir, FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.CreateDirectory(tempDir)
End Sub
Public Shared Sub Save(ByVal Output As String)
Dim G As New Windows.Media.Imaging.GifBitmapEncoder
Dim X As New List(Of IO.FileStream)
For Each Fi As String In My.Computer.FileSystem.GetFiles(tempDir, FileIO.SearchOption.SearchTopLevelOnly, "*.png")
Dim TempStream As New IO.FileStream(Fi, IO.FileMode.Open)
Dim Frame = Imaging.BitmapFrame.Create(TempStream)
X.Add(TempStream)
G.Frames.Add(Frame)
Next
Dim FS As New IO.FileStream(Output, IO.FileMode.OpenOrCreate)
G.Save(FS)
FS.Close()
For Each St As IO.FileStream In X
St.Close()
Next
End Sub
Public Shared Sub Start()
snap = New System.Threading.Thread(AddressOf Snapshot)
snap.Start()
End Sub
Public Shared Sub [Stop]()
snap.Abort()
End Sub
Private Shared Function FormatString(ByVal S As String, ByVal places As Integer, ByVal character As Char) As String
If S.Length >= places Then Return S
For X As Integer = S.Length To places
S = character & S
Next
Return S
End Function
End Class
Public Class ScreenRecorder
Private Shared tempDir As String = My.Computer.FileSystem.SpecialDirectories.Temp & "\snapshot\"
Private Shared snap As New System.Threading.Thread(AddressOf Snapshot)
Private Shared _Bounds As System.Drawing.Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds
Public Shared Property Bounds() As System.Drawing.Rectangle
Get
Return _Bounds
End Get
Set(ByVal value As System.Drawing.Rectangle)
_Bounds = value
End Set
End Property
Private Shared Sub Snapshot()
If Not My.Computer.FileSystem.DirectoryExists(tempDir) Then _
My.Computer.FileSystem.CreateDirectory(tempDir)
Dim Co As Integer = 0
Do
Co += 1
System.Threading.Thread.Sleep(50)
Dim X As New System.Drawing.Bitmap(_Bounds.Width, _Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Using G = System.Drawing.Graphics.FromImage(X)
G.CopyFromScreen(_Bounds.Location, New System.Drawing.Point(), _Bounds.Size)
Dim CurBounds As New System.Drawing.Rectangle(System.Windows.Forms.Cursor.Position - Bounds.Location, System.Windows.Forms.Cursor.Current.Size)
Windows.Forms.Cursors.Default.Draw(G, CurBounds)
End Using
Dim FS As New IO.FileStream(tempDir & FormatString(Co.ToString, 5, "0"c) & ".Gif", IO.FileMode.OpenOrCreate)
X.Save(FS, System.Drawing.Imaging.ImageFormat.Gif)
X.Dispose()
FS.Close()
Loop
End Sub
Public Shared Sub ClearRecording()
If My.Computer.FileSystem.DirectoryExists(tempDir) Then _
My.Computer.FileSystem.DeleteDirectory(tempDir, FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.CreateDirectory(tempDir)
End Sub
Public Shared Sub Save(ByVal Output As String)
Dim X As New List(Of IO.FileStream)
For Each Fi As String In My.Computer.FileSystem.GetFiles(tempDir, FileIO.SearchOption.SearchTopLevelOnly, "*.png")
Dim TempStream As New IO.FileStream(Fi, IO.FileMode.Open)
Next
Dim FS As New IO.FileStream(Output, IO.FileMode.Create)
For Each St As IO.FileStream In X
St.Close()
Next
End Sub
Public Shared Sub Start()
snap = New System.Threading.Thread(AddressOf Snapshot)
snap.Start()
End Sub
Public Shared Sub [Stop]()
snap.Abort()
End Sub
Private Shared Function FormatString(ByVal S As String, ByVal places As Integer, ByVal character As Char) As String
If S.Length >= places Then Return S
For X As Integer = S.Length To places
S = character & S
Next
Return S
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ScreenRecorder.Start()
Me.Button1.Enabled = False
Me.Button3.Enabled = False
Me.Button4.Enabled = False
Me.Button5.Enabled = False
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ScreenRecorder.Stop()
Me.Button1.Enabled = True
Me.Button3.Enabled = True
Me.Button4.Enabled = True
Me.Button5.Enabled = True
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ScreenRecorder.Save("")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ScreenRecorder.Bounds = New System.Drawing.Rectangle(300, 300, 500, 300)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ScreenRecorder.ClearRecording()
End Sub
Private Sub ScreenRecorder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Chr(Asc("S")) Then
Me.WindowState = FormWindowState.Maximized
ScreenRecorder.Stop()
Me.Button1.Enabled = True
Me.Button3.Enabled = True
Me.Button4.Enabled = True
Me.Button5.Enabled = True
End If
End Sub
End Class
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ScreenRecorder.Save("")
End Sub
try ^^Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ScreenRecorder.Save("c:\SR1.gif")
End Sub
Error 2 Type 'Windows.Media.Imaging.GifBitmapEncoder' is not defined.
Error 3 'BitmapFrame' is not a member of 'Imaging'.
Uhm..
its ok but i fixed up your code except i got the same problem i cant make it save correctly...
Code:Me.Button1.Enabled = True Me.Button3.Enabled = True Me.Button4.Enabled = True Me.Button5.Enabled = True

