bigfoot3d
Well-known member
So I am trying to capture a screen and use GetDIBits to get the bytes of the screen capture for a network transfer.  On the other side the bytes will be received and processed by SetDIBits for further processing.
Well maybe you can tell me what I am doing wrong here. The GetDIBits returns a result of 1050 which is the height of my screen. However SetDIBits returns 0 every time. What am I doing wrong?
Thanks!
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
If any more clarification is needed, please let me know!
Thanks for your help in advance!
	
		
			
		
		
	
				
			Well maybe you can tell me what I am doing wrong here. The GetDIBits returns a result of 1050 which is the height of my screen. However SetDIBits returns 0 every time. What am I doing wrong?
Thanks!
			
				VB.NET:
			
		
		
		        'Bitblt to compare and get differences.
        BitBlt(IncompDC3, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, _
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, OrigScreen, 0, 0, &HCC0020)
        BitBlt(IncompDC3, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, _
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, IncompDC2, 0, 0, &H660046)
        
        CompDC3 = CreateCompatibleDC(IncompDC3)
        FW3 = GetDeviceCaps(IncompDC3, 8)
        FH3 = GetDeviceCaps(IncompDC3, 10)
        CompBMP3 = CreateCompatibleBitmap(IncompDC3, FW3, FH3)
        hBMPOld3 = SelectObject(CompDC3, CompBMP3)
        BitBlt(CompDC3, 0, 0, FW3, FH3, IncompDC3, 0, 0, &HCC0020)
        NewBMP3 = SelectObject(CompDC3, hBMPOld3)
        'See the result, is this what I want?
        PictureBox4.Image = Image.FromHbitmap(NewBMP3)
        Dim bi24BitInfo As New BITMAPINFO
        With bi24BitInfo.bmiHeader
            .biSize = 40 'System.Runtime.InteropServices.Marshal.SizeOf(GetType(BITMAPINFO))
            .biBitCount = 24
            .biCompression = 0 ' BI_RGB
            .biPlanes = 1
            .biWidth = FW3
            .biHeight = FH3
            .biXPelsPerMeter = 0
            .biYPelsPerMeter = 0
            .biSizeImage = FW3 * FH3 * 3
            .biClrUsed = 0
            .biClrImportant = 0
        End With
        Dim textureImg(FW3 * FH3 * 3 - 1) As Byte
        Dim gch As GCHandle = GCHandle.Alloc(textureImg, GCHandleType.Pinned)
        'Get the bits of the memory.
        Dim result As Integer = GetDIBits(IncompDC3, NewBMP3, 0, FH3, gch.AddrOfPinnedObject, bi24BitInfo, 0)
        ' Result should be > 0
        MsgBox("GetDIBits Result: " + result.ToString)
        'Testing without GCHandle
        'Dim result As Integer = GetDIBits(IncompDC3, NewBMP3, 0, FH3, textureImg, bi24BitInfo, 0)
        gch.Free()
        Dim filewriter As New System.IO.FileStream("C:\RemoteHandImages\imagetxtinfo.txt", IO.FileMode.Create)
        filewriter.Write(textureImg, 0, textureImg.Length)
        filewriter.Flush()
        filewriter.Close()
        'Setup new variables as if it was on the receiving computer of a network stream.
        Dim FW4, FH4, CompDC4, CompBMP4, hBMPOld4, NewBMP4 As Integer
        Dim IncompDC4 As Integer
        Dim Screen4 As Graphics
        Screen4 = Graphics.FromImage(New System.Drawing.Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, _
 System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height))
        IncompDC4 = Screen4.GetHdc
        CompBMP4 = CreateCompatibleBitmap(IncompDC4, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, _
 System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
        CompDC4 = CreateCompatibleDC(IncompDC4)
        
        Dim gch2 As GCHandle = GCHandle.Alloc(textureImg, GCHandleType.Pinned)
        result = SetDIBits(IncompDC4, CompBMP4, 0, bi24BitInfo.bmiHeader.biHeight, gch2.AddrOfPinnedObject, bi24BitInfo, 0)
        'Testing without GCHandle
        'SetDIBits(IncompDC4, NewBMP4, 0, bi24BitInfo.bmiHeader.biHeight, textureImg, bi24BitInfo, 0)
        'Result should be > 0 !  For some reason here is always now 0
        MsgBox("SetDIBits Result: " + result.ToString)
        gch2.Free()
        CompDC4 = CreateCompatibleDC(IncompDC4)
        FW4 = GetDeviceCaps(IncompDC4, 8)
        FH4 = GetDeviceCaps(IncompDC4, 10)
        CompBMP4 = CreateCompatibleBitmap(IncompDC4, FW4, FH4)
        hBMPOld4 = SelectObject(CompDC4, CompBMP4)
        BitBlt(CompDC4, 0, 0, FW4, FH4, IncompDC4, 0, 0, &HCC0020)
        NewBMP4 = SelectObject(CompDC4, hBMPOld4)
        'Save image to see if it worked
        Image.FromHbitmap(NewBMP4).Save("C:\RemoteHandImages\hmm69.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
        
        'Image saved for comparison.
PictureBox4.Image.Save("C:\RemoteHandImages\hmm3.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
        Screen3.Dispose()If any more clarification is needed, please let me know!
Thanks for your help in advance!
 
	 
 
		