我想截取屏幕截图而不将其保存到磁盘上。 这一切都在vb.net中 因为我想流式传输屏幕,所以我每隔0.5秒运行一次屏幕截图并加载它,所以它不必那么重。 以下是我目前使用的代码:
Dim timestamp As String = CLng(DateTime.UtcNow.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
screenshot.Save(Path.GetTempPath & "\stream_video\screenshot.jpg", Imaging.ImageFormat.Jpeg)
My.Computer.Network.UploadFile(Path.GetTempPath & "\stream_video\screenshot.jpg", server_total & "upload.php")
IO.File.Delete(Path.GetTempPath & "\stream_video\screenshot.jpg")
GC.Collect() 'Garbage Collection
我怎样才能使它尽可能流畅和优化?
[抱歉我的英语不好]。