Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

ScreenCapture [Faster Screenshots]

I needed a faster way to take screenshots so I threw this class together because Graphics.CopyFromScreen was too slow for what I was working on.

<3 BitBlt

VB.NET
Spoiler (Click to View)

C#
Spoiler (Click to View)

Usage:
Code
//C#
Bitmap screen = ScreenCapture.GetScreenshot()
Bitmap partofscreen = Screen.GetFromScreen(new Point(530, 319), 100, 100);

'VB.NET
Dim screen As New Bitmap = ScreenCapture.GetScreenshot()
Dim partofscreen As New Bitmap = Screen.GetFromScreen(new Point(530, 319), 100, 100)
I'm not 100% sure without testing because I handle this a bit differently, but you may run into scaling issues with this code if the computer's DPI isn't set to 100%. You may want to test for that! :)
Thanks a lot for the sharing, appreciate it ! Will add this to my library collection ;)
Looks pretty good, I have always wanted a Screen Capture program that would allow me to upload directly to a FTP server, so I would have better control over all my images.
[Image: M6MscUn.gif]

(May 7, 2016 11:41 PM)6e756c6c Wrote:  I'm not 100% sure without testing because I handle this a bit differently, but you may run into scaling issues with this code if the computer's DPI isn't set to 100%. You may want to test for that! :)

Didn't even occur to me, I'm on mobile right now and I'll definitely do some testing later. Thanks foe the suggestion!
(May 7, 2016 11:41 PM)6e756c6c Wrote:  I'm not 100% sure without testing because I handle this a bit differently, but you may run into scaling issues with this code if the computer's DPI isn't set to 100%. You may want to test for that! :)

I tested it and it will not show the entire screen if the DPI is not 100%.

Spoiler (Click to View)

I don't know how to fix it apperantly G.CopyFromScreen has GDI issues too. Maybe someone else knows how to fix the issue.
I found a fix for what Aeonhack had suggested which was to use Graphics.DpiX / Graphics.DpiY.
thanks for sharing this with us ;)
try this script

Code
'for timers

        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
        Timer1.Enabled = False
        Me.Opacity = 100
    

'For button when captured

        PictureBox1.Show()
        Me.Opacity = 0
        Timer1.Enabled = True
        Button2.Enabled = True
  

For save the file

        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save File"
            savefiledialog1.FileName = "Capture"
            savefiledialog1.Filter = "Bitmap (*.bmp;*.dib)|*.bmp;*.dib|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|TIFF (*.tif;*.tiff)|*.tif;*.tiff|PNG (*.png)|*.png"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            End If
        Catch ex As Exception
            ' Do Nothing
        End Try
(May 13, 2016 02:28 AM)Luciffer Wrote:  try this script

Code
'for timers

        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
        Timer1.Enabled = False
        Me.Opacity = 100
    

'For button when captured

        PictureBox1.Show()
        Me.Opacity = 0
        Timer1.Enabled = True
        Button2.Enabled = True
  

For save the file

        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save File"
            savefiledialog1.FileName = "Capture"
            savefiledialog1.Filter = "Bitmap (*.bmp;*.dib)|*.bmp;*.dib|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|TIFF (*.tif;*.tiff)|*.tif;*.tiff|PNG (*.png)|*.png"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            End If
        Catch ex As Exception
            ' Do Nothing
        End Try
Are you retarded..?
Just testing "how much faster"
Malem VS Zilog80 Screenshot (Click to View)

Edit:
The above results: Windows 10. C2Duo @ 2.67 Ghz. 4 GB RAM.$25 cheap NVIDIA graphics card. 1280 x 1024

The next results: Windows 10. i7 4790K @ 4.0 Ghz. 16 GB RAM. 970 NVIDIA graphics card. 1920 x 1080: (Click to View)

WTF 😧
thanks for sharing this with us ;)
(May 13, 2016 06:53 AM)Zilog80 Wrote:  Just testing "how much faster"
Malem VS Zilog80 Screenshot (Click to View)

Edit:
The above results: Windows 10. C2Duo @ 2.67 Ghz. 4 GB RAM.$25 cheap NVIDIA graphics card. 1280 x 1024

The next results: Windows 10. i7 4790K @ 4.0 Ghz. 16 GB RAM. 970 NVIDIA graphics card. 1920 x 1080: (Click to View)

WTF 😧

I'm not using DirectX, of course it's not going to come close to that. Lol.
You can't get below 50ms constantly in 1080p with WINAPI, so, you'll get at most 20 fps, if i recall, the tops were really 15-16, this is with Aero ON, which is default since Vista days.

I don't know how exactly Nanocore works but i'm pretty sure it's not 30+ full screenshots per second, he probably handles it on a changed area of sorts, it works quite good but don't expect to hit 30 without DirectX, and nanocore doesn't use DirectX, nor do i know if it's possible or that easy.
(May 14, 2016 01:37 PM)He B TeMy Wrote:  You can't get below 50ms constantly in 1080p with WINAPI, so, you'll get at most 20 fps, if i recall, the tops were really 15-16, this is with Aero ON, which is default since Vista days.

I don't know how exactly Nanocore works but i'm pretty sure it's not 30+ full screenshots per second, he probably handles it on a changed area of sorts, it works quite good but don't expect to hit 30 without DirectX, and nanocore doesn't use DirectX, nor do i know if it's possible or that easy.

It checks what has changed on the screen and sends the changes. Pretty sure it still captures the whole screen, but for bandwidth reasons it only sends the changes. At least this is what I heard.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by icemanonadderallMay 19, 2018 10:27 AM 9 423 May 19, 2018 10:27 AM
Last Post: Dalvik
[.NET] by anthoo12Feb 2, 2018 11:46 PM 16 2,064 Feb 2, 2018 11:46 PM
Last Post: v.e.n.o.m
[.NET] by BarretJan 16, 2018 02:44 PM 6 433 Jan 16, 2018 02:44 PM
Last Post: Ninja