Guest User

Untitled

a guest
Aug 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Net.Mail
  3.  
  4. Imports System.IO.Compression
  5. Imports System.Xml
  6.  
  7. Public Class Form2
  8. Dim mydataandtimeforsave As String = DateTime.Now.ToString("yyyyMMddHHmmss")
  9. Dim frame As Long 'individual frames
  10. Dim tempdir As String = "C:dirorg/" ' images temp directory
  11. Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  12. If TextBox1.Text = "" Then
  13. TextBox1.Text = 1
  14. End If
  15.  
  16. End Sub
  17.  
  18. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  19.  
  20. capturex()
  21. 'save()
  22. End Sub
  23. Public Sub capturex()
  24. Try
  25.  
  26. Dim area As Rectangle
  27. Dim graph As Graphics
  28. Dim captured As Bitmap
  29. area = Screen.PrimaryScreen.Bounds
  30. captured = New System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
  31. graph = Graphics.FromImage(captured)
  32.  
  33. graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
  34. ' you will need IF statement if you have checkbox
  35. If CheckBox1.Checked = True Then
  36. Cursor.Draw(graph, New Rectangle(New Point(Cursor.Position.X - Cursor.HotSpot.X, Cursor.Position.Y - Cursor.HotSpot.Y), Cursor.Size))
  37.  
  38. End If
  39. Dim strings As String
  40.  
  41. strings = frame
  42. captured.Save(tempdir & "" & strings & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
  43. frame += 1
  44. Label2.Text = "TIME: " & frame
  45. Catch ex As Exception
  46.  
  47. End Try
  48. End Sub
  49.  
  50. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  51. Timer1.Start()
  52. End Sub
  53.  
  54. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  55.  
  56. Me.Timer1.Interval = TimeSpan.FromSeconds(TextBox1.Text).TotalMilliseconds
  57. capturex()
  58.  
  59. End Sub
  60.  
  61. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  62. renameFilesInFolder()
  63.  
  64.  
  65. '-framerate 3 -i "Imgp%%04d.jpg" -s 720x480 test.avi)
  66. End Sub
  67. Private Sub renameFilesInFolder()
  68. Dim sourcePath As String = "C:dirorg/"
  69. Dim searchPattern As String = "*.jpg"
  70. Dim i As Integer = 0
  71. For Each fileName As String In Directory.GetFiles(sourcePath, searchPattern, SearchOption.AllDirectories)
  72. File.Move(Path.Combine(sourcePath, fileName), Path.Combine(sourcePath, "Imgp" & i & "d.jpg"))
  73. i += 1
  74. Next
  75. End Sub
  76.  
  77. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  78. With SaveFileDialog1
  79. .DefaultExt = ".avi"
  80. .FilterIndex = 1
  81. .Filter = "Avi Files (*.avi)|*.avi|All files (*.*)|*.*"
  82. End With
  83. SaveFileDialog1.ShowDialog()
  84. End Sub
  85.  
  86. Private Sub SaveFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
  87.  
  88. Dim args As String 'declare args
  89. args = "-r 1/.1 -i " & "C:dirorg" & "%01d.jpg -c:v libx264 -r 80 -pix_fmt yuv420p " & Chr(34) & SaveFileDialog1.FileName & Chr(34) 'set ffmpeg arguments
  90. Dim proc As New Process
  91. Dim proci As New ProcessStartInfo
  92. proci.FileName = "C:dirorgffmpeg.exe"
  93. proci.Arguments = args
  94. proci.WindowStyle = ProcessWindowStyle.Hidden
  95. proci.CreateNoWindow = True
  96. proci.UseShellExecute = False
  97. proc.StartInfo = proci
  98. proc.Start()
  99. Do Until proc.HasExited = True
  100. Me.Text = "Saving"
  101. Loop
  102. Me.Text = "your video done"
  103.  
  104. MsgBox("Done")
  105. compimages()
  106. BackgroundWorker1.RunWorkerAsync()
  107. MsgBox("All Done")
  108. Dim directoryName As String = tempdir
  109.  
  110. For Each deleteFile In Directory.GetFiles(directoryName, "*.jpg", SearchOption.TopDirectoryOnly)
  111. File.Delete(deleteFile)
  112. Next
  113. End Sub
  114.  
  115. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  116. Timer1.Stop()
  117. End Sub
  118.  
  119. Public Sub compimages()
  120. 'To zip a directory
  121. Dim mydataandtimeforsave = DateTime.Now.ToString("yyyyMMddHHmmss")
  122. Dim Compressed = ZipDirectory("C:dirorg")
  123. File.WriteAllBytes("C:dirorgimages.zip", Compressed)
  124. End Sub
  125. Public Sub uncompimages()
  126. 'To unzip a zipped file
  127. Dim Compressed = File.ReadAllBytes("C:dirorgimages" & mydataandtimeforsave & ".zip")
  128. UnzipDirectory(Compressed, "C:dirorg")
  129. End Sub
  130. Public Function ZipDirectory(DirPath As String) As Byte()
  131. If Not Directory.Exists(DirPath) Then Return Nothing
  132.  
  133. Dim Directories = Directory.GetDirectories(DirPath, "*", SearchOption.AllDirectories)
  134. Dim Files = Directory.GetFiles(DirPath, "*", SearchOption.AllDirectories)
  135.  
  136. Dim X As New XmlDocument
  137. Dim RootNode = X.CreateElement("Content")
  138. Dim DirsNode = X.CreateElement("Directories")
  139. Dim FilesNode = X.CreateElement("Directories")
  140.  
  141. X.AppendChild(RootNode)
  142. RootNode.AppendChild(DirsNode)
  143. RootNode.AppendChild(FilesNode)
  144.  
  145. For Each d In Directories
  146. Dim DirNode = X.CreateElement("Directory")
  147. Dim PathAttrib = X.CreateAttribute("Path")
  148. PathAttrib.Value = d.Replace(DirPath & "", "") 'Create relative paths
  149. DirNode.Attributes.Append(PathAttrib)
  150. DirsNode.AppendChild(DirNode)
  151. Next
  152.  
  153. For Each f In Files
  154. Dim FileNode = X.CreateElement("File")
  155. Dim PathAttrib = X.CreateAttribute("Path")
  156. PathAttrib.Value = f.Replace(DirPath & "", "") 'Create relative paths
  157. FileNode.Attributes.Append(PathAttrib)
  158. FileNode.InnerText = Convert.ToBase64String(File.ReadAllBytes(f))
  159. FilesNode.AppendChild(FileNode)
  160. Next
  161.  
  162. Using Mem As New MemoryStream()
  163. X.Save(Mem)
  164. Dim AllContentsAsByteArray = Mem.ToArray()
  165. Dim CompressedContent = CompressArray(AllContentsAsByteArray)
  166. Return CompressedContent
  167. End Using
  168. End Function
  169.  
  170. Public Sub UnzipDirectory(compressed() As Byte, outputPath As String)
  171. If Not Directory.Exists(outputPath) Then Directory.CreateDirectory(outputPath)
  172.  
  173. Dim Uncompressed = DecompressArray(compressed)
  174.  
  175. Dim X As New XmlDocument
  176.  
  177. Using Mem As New MemoryStream(Uncompressed)
  178. X.Load(Mem)
  179.  
  180. Dim RootNode = X.FirstChild
  181. Dim DirsNode = RootNode.FirstChild
  182. Dim FilesNode = RootNode.FirstChild.NextSibling
  183.  
  184. For Each ChildDir In DirsNode.ChildNodes
  185. Directory.CreateDirectory(Path.Combine(outputPath, DirectCast(ChildDir, XmlNode).Attributes.Item(0).Value))
  186. Next
  187.  
  188. For Each ChildFile In FilesNode.ChildNodes
  189. Dim FilePath = Path.Combine(outputPath, DirectCast(ChildFile, XmlNode).Attributes.Item(0).Value)
  190. Dim Content = Convert.FromBase64String(DirectCast(ChildFile, XmlNode).InnerText)
  191. File.WriteAllBytes(FilePath, Content)
  192. Next
  193. End Using
  194. End Sub
  195.  
  196. Private Function CompressArray(ByVal content() As Byte) As Byte()
  197. Using outFile As New MemoryStream()
  198. Using Compress As New GZipStream(outFile, CompressionMode.Compress)
  199. Compress.Write(content, 0, content.Length)
  200. End Using
  201.  
  202. Return outFile.ToArray()
  203. End Using
  204. End Function
  205.  
  206. Private Function DecompressArray(ByVal content() As Byte) As Byte()
  207. Using outFile As New MemoryStream()
  208. Using inFile As New MemoryStream(content)
  209. Using Compress As New GZipStream(inFile, CompressionMode.Decompress)
  210. Dim buffer(1023) As Byte
  211. Dim nRead As Integer
  212. Do
  213. nRead = Compress.Read(buffer, 0, buffer.Length)
  214. outFile.Write(buffer, 0, nRead)
  215. Loop While nRead > 0
  216. End Using
  217. End Using
  218.  
  219. Return outFile.ToArray()
  220. End Using
  221. End Function
  222. Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  223. Using mail As New MailMessage
  224. mail.From = New MailAddress("helderventura227@gmail.com")
  225. mail.To.Add(My.Settings.destinationx$)
  226. mail.Body = My.Settings.bodyx$
  227.  
  228. Dim attach As New Attachment("C:dirorgimages.zip")
  229. mail.Attachments.Add(attach)
  230.  
  231. mail.Subject = My.Settings.subjectx$
  232. mail.Priority = MailPriority.High
  233. Using SMTP As New SmtpClient
  234.  
  235. SMTP.EnableSsl = True
  236. SMTP.Port = "587"
  237. SMTP.Host = "smtp.gmail.com"
  238. SMTP.Credentials = New Net.NetworkCredential("helderventura227@gmail.com", "u>#4TBOw")
  239. SMTP.Send(mail)
  240. End Using
  241. End Using
  242.  
  243. End Sub
  244.  
  245. Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
  246. MsgBox("Email has been sent successfully!", MsgBoxStyle.Information)
  247. End Sub
  248. End Class
Add Comment
Please, Sign In to add comment