VB.NET Screen Capture - vb.net

Hello all i am using the below code to capture the screenshot of the black panel of my window form in visual basic 2005.
My problem is that I want the red border image to come in between and to be full.
My code :
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(618, 191, 850, 455, bounds.Size, CopyPixelOperation.SourceCopy)
screenshot.Save("d:\\dcap.bmp", Imaging.ImageFormat.Bmp) `

Your code works well just set the bounds to zero
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("d:\\dcap.jpg", Imaging.ImageFormat.Bmp)

Related

Vb.Net Application Screen Capture and Save it as a pdf

I have this small application which capture the screen and save it as a pdf. I am running this application on my PC which has 1080P primary display and 1080P TV as an extended display. When i put the application on the extended TV display (full screen mode) it doesn't capture entire screen. It capture only 1/4 of the screen. But i want to capture the entire screen. How do i fix this. Please help
Here is the code;
Private Sub SaveForm_shift1()
Dim yesterday As String = DateTime.Now.ToString("yyyy-MM-dd")
Dim filePath As String = "C:\Autodesk" + yesterday + ".jpg"
Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
Try
gfxScreenshot.Dispose()
' Save the screenshot
bmpScreenshot.Save(filePath)
saveToPdf_shift1(filePath)
deleteImg(filePath)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Use this function to get a Bitmap with all the screens
Public Function GetScreenShot() As Bitmap
Dim bmp As Bitmap = New Bitmap(Screen.AllScreens.Sum(Function(s As Screen) s.Bounds.Width),
Screen.AllScreens.Max(Function(s As Screen) s.Bounds.Height))
Dim gfx As Graphics = Graphics.FromImage(bmp)
gfx.CopyFromScreen(New Point(0, 0), New Point(0, 0), bmp.Size)
Return bmp
End Function
If you have strange staggered screen positions, the empty areas will be black in the resulting bitmap.

upload a screenshot without save it in vb.net

I would like to take a screenshot without saving it to the disk.
All this in vb.net
Since I would like to stream the screen I run a screenshot and load it every 0.5 seconds, so it does not have to be that heavy.
Below is the code I currently use:
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
how could I make it as fluid and optimized as possible?
[Sorry for my bad english].

Set picturebox image in thread

i'm trying set picturebox image in thread but i cant set it
take screenshot in specific window
set picturebox image to screenshot
This codes can get screenshot in specific window but cant set picturebox image to it. Whats wrong?
Public Function PrintWindow(hwnd As IntPtr) As Bitmap
Dim rc As RECT
GetWindowRect(hwnd, rc)
Dim bmp As New Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb)
Dim gfxBmp As Graphics = Graphics.FromImage(bmp)
Dim hdcBitmap As IntPtr = gfxBmp.GetHdc()
PrintWindow(hwnd, hdcBitmap, 0)
gfxBmp.ReleaseHdc(hdcBitmap)
gfxBmp.Dispose()
Return bmp
End Function
Dim OverviewRefresherThread As New Thread(AddressOf RefreshOverviewThread)
Public Sub RefreshOverviewThread()
Do
MainWindow.PictureBox.Image = PrintWindow(WindowHandle("TEST"))
Loop
End Sub
thanks...
Am I right? You are tying to get a screenshot from Whatever and transfer it in Picturebox? If so then take a look at this code.
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.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
This code takes a screenshot of the desktop and transfer it in picbox.
You can see tutorial here.
http://vb6.wonderhowto.com/how-to/capture-desktop-screen-with-vb-net-0158485/
If im not mistaken you already done with the screenshot you just need to transfer it and thats your problem.

Save multiple screenshots

I'm using this code to take a screenshot with my VB app:
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("c:\Screenshot.png", Imaging.ImageFormat.Png)
End Sub
How would it be possible to save multiple screenshots in the same map? (eg. screenshot1.png, screenshot2.png, ....)
Thanks again.
PS: also if there are 2 monitors, is there a way to take a 'fullscreen' screenshot?
Posting An Answer Because of the turn around time
Even though your original code you have posted wont compile on my system, With my comment as well as Pro Grammers comment, this should do the trick.
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
Dim TimeStamp = DateTime.Now.ToLongTimeString & "_" & DateTime.Now.ToShortDateString()
Label1.Text = TimeStamp
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("c:\Screenshot_" & TimeStamp & ".png", Imaging.ImageFormat.Png)
Have a play around with the time stamp and see what works for you.

Converting Bitmap to RGB in VB

Please see the attatched code below. I have managed to take a screenshot of my computing using VB and I have stored it as a bitmap. I want to convert this bitmap (quickly!) to an array of rgb values.
Any simple code that can do this?
Cheers
Martin
' Capture screen code
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(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
' Display the captured image
Display.Image = screenshot
An example is in the Bitmap.LockBits documentation:
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx#Y856