Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

VB.net Screen Capture Image Problem!

$
0
0
Good day dreamincoders

here's my problem:

i always get half or 1/3 of the image when i'm taking a screen capture.

here's my code on server form

dim bytedata(100000) as byte
Private Sub OnReceived(ByVal ar As IAsyncResult)
        Dim client As Socket = ar.AsyncState
        client.EndReceive(ar)
        Dim bytesRec As Byte() = bytedata
        Dim message As String = System.Text.ASCIIEncoding.ASCII.GetString(bytesRec)
        If caps = 1 Then
            caps = 0
            Dim path As String
            path = System.Windows.Forms.Application.StartupPath.ToString() + "\T1.Bmp"
            Dim fli As New FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)
            fli.Write(bytesRec, 0, bytesRec.Length)
            fli.Close()
            Dim s As New FileStream(path, FileMode.Open, FileAccess.Read)
            PictureBox1.Image = Image.FromStream(s)
            s.Close()
        End If
        Read(message)
        'sortDelim()
        Array.Clear(bytedata, 0, bytedata.Length)
        clientSocket.BeginReceive(bytedata, 0, bytedata.Length, SocketFlags.None, _
                                  New AsyncCallback(AddressOf OnReceived), clientSocket)
        clientSocket = ar.AsyncState



and here's for client
 Private Sub capturenow()
        Timer1.Enabled = True
    End Sub

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        CaptureScreen()
        Dim b(10000000) As Byte
        Dim path As String
        path = System.Windows.Forms.Application.StartupPath.ToString() + "\T1.bmp"
        oBackground.Save(path)
        Dim fl As New FileStream(path, FileMode.Open, FileAccess.Read)
        Dim l As Integer
        l = fl.Read(b, 0, fl.Length)
        fl.Close()
        clientSocket.Send(b, l, SocketFlags.None)
        File.Delete(path)
        Timer1.Enabled = False
    End Sub

    Private Sub CaptureScreen()
        Dim hSDC, hMDC As Integer
        Dim hBMP, hBMPOld As Integer
        Dim r As Integer
        hSDC = CreateDC("DISPLAY", "", "", "")
        hMDC = CreateCompatibleDC(hSDC)
        FW = GetDeviceCaps(hSDC, 8)
        FH = GetDeviceCaps(hSDC, 10)
        hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
        hBMPOld = SelectObject(hMDC, hBMP)
        r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
        hBMP = SelectObject(hMDC, hBMPOld)
        r = DeleteDC(hSDC)
        r = DeleteDC(hMDC)
        oBackground = Image.FromHbitmap(New IntPtr(hBMP))
        DeleteObject(hBMP)
    End Sub




the output image attached here is the image i always received in picturebox1 of server. please help me seniors thanks.

Posted Image

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>