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

.NET 

Screen Capture

Hello is there anyway to capture a part of the screen and stream it too an application form via visual studio any help is appreciated Thanks!
Hi, yes there is a way to capture a part of the computer screen (you can look this up on Google on how you can do this). Although, I'm not sure what you mean by "stream it too an application form." Do you mean stream it to another form that is integrated into your project (e.g: you want to stream the specific part of the screen onto Form1.vb, Form2.vb, etc) or onto an external application?
Yes that's what i mean preview it live basically via a form :)
(Mar 15, 2017 11:35 AM)ryanrl Wrote:  Yes that's what i mean preview it live basically via a form :)

If you want to achieve that you need to add a picture box control and a timer control to your form (which can both be found in the Visual Studio toolbox). Using the timer's tick event you can update a picture box's image at a specific interval.

Here's an example code of what I mean.

Code
Public Class Form1

    Private Function ScreenShot() As Bitmap
        Dim screenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Using g As Graphics = Graphics.FromImage(screenGrab)
            g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
            Return screenGrab
        End Using
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        PictureBox1.Image = ScreenShot()
    End Sub
End Class

The code above will update the picture box's image every 1 second with a screenshot of the computer screen. If you want to change how fast/slow the picture box should be updated, you have to change the interval speed of the timer.

I think this should give you a general idea on how you can stream the computer screen to a form. Now all you need to do is figure out how to take a screenshot of the screen at specific coordinates. 👍
Taking screenshots isn't going to give you much FPS.
If you really want good Streaming with Audio use my method.
You could write a programm that starts VLC with arguments hidden
i can give you my arguments that i have streamed with perfectly

Stream
Code
// Better store each line in StringBuilder
var streamCommand = "-I dummy --dummy-quiet dshow:// :dshow-vdev=screen-capture-recorder dshow:// :dshow-vdev=screen-capture-recorder :dshow-aspect-ratio=16:9 :dshow-fps=30 :live-caching=200 :sout=#transcode{vcodec=mp2v,vb=800,acodec=mpga,ab=128,channels=2,samplerate=44100}:rtp{dst=RECEIVERIPHERE,port=1234,mux=ts} :sout-keep";

var processStartInfo = new ProcessStartInfo {
                FileName = VlcPath,
                Arguments = streamCommand
};
Process.Start(processStartInfo);

and on the Receiving end you could do the same or use https://github.com/ZeBobo5/Vlc.DotNet,

// Receive
Code
private string receiveCommand => "--qt-start-minimized " +
                                                "--qt-fullscreen-screennumber=1 " +
                                                "--no-qt-fs-controller " +
                                                "--qt-notification 0 " +
                                                "--no-video-title  " +
                                                "--fullscreen " +
                                                "rtp://@:1234 " +
                                                ":network-caching=500";

var processStartInfo = new ProcessStartInfo {
                FileName = VlcPath,
                Arguments = streamCommand
};
Process.Start(processStartInfo);


If used this before and it works like charm, VLC is completelly hidden you wont notice it unless you see it in the Taskmanager,
this way you would get much more FPS depending on the Connection.
Thanks for the reply i have sorted it out now basically i used getwindow function to hook on applications Example ("runescape") then used Mouse up/down events to make a region to select areas of the given application.
The reason i wanted to do this was so i could minimize runescape with a movable overlay over fullscreen applications.
example:
Thanks for your help.🤝
(Mar 15, 2017 12:22 PM)My Computer Wrote:  If you want to achieve that you need to add a picture box control and a timer control to your form (which can both be found in the Visual Studio toolbox). Using the timer's tick event you can update a picture box's image at a specific interval.

Here's an example code of what I mean.

Code
Public Class Form1

    Private Function ScreenShot() As Bitmap
        Dim screenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Using g As Graphics = Graphics.FromImage(screenGrab)
            g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
            Return screenGrab
        End Using
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        PictureBox1.Image = ScreenShot()
    End Sub
End Class

The code above will update the picture box's image every 1 second with a screenshot of the computer screen. If you want to change how fast/slow the picture box should be updated, you have to change the interval speed of the timer.

I think this should give you a general idea on how you can stream the computer screen to a form. Now all you need to do is figure out how to take a screenshot of the screen at specific coordinates. 👍

You dont have to re-declare the size and such every time, do you? The screen size will not change each tick.
(Mar 16, 2017 11:09 AM)Ninja Wrote:  You dont have to re-declare the size and such every time, do you? The screen size will not change each tick.

Well technically, the screen size could change after a tick (that is, if the user for some odd reason changed their resolution while the program was running). But I see what you mean because it would be really unlikely for the user to change their resolution while the program is running.

This is what the picture box would look like if you kept the screen boundaries variables constant while the resolution on the screen has been changed to a lower one:

Spoiler (Click to View)
(Mar 16, 2017 12:39 PM)My Computer Wrote:  Well technically, the screen size could change after a tick (that is, if the user for some odd reason changed their resolution while the program was running). But I see what you mean because it would be really unlikely for the user to change their resolution while the program is running.

This is what the picture box would look like if you kept the screen boundaries variables constant while the resolution on the screen has been changed to a lower one:

Spoiler (Click to View)
I bet you can just hook something and find out when the resolution changes.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by salemxx66Sep 30, 2021 08:39 PM 0 130 Sep 30, 2021 08:39 PM
Last Post: salemxx66
[C#] by hacker dzApr 22, 2021 08:27 AM 3 326 Apr 22, 2021 08:27 AM
Last Post: Scapula™
[C#] by ForceJewOct 6, 2016 11:51 AM 26 664 Oct 6, 2016 11:51 AM
Last Post: CodeAssassin