CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 45

Threaded View

  1. #1
    Join Date
    Oct 2013
    Posts
    39

    [win32] Send bitmap over socket

    I want to send a bitmap over socket, however since I kinda work with bitmaps for the first time, I dont really have an idea how to do that, so far I have code that gets the screenshot of the screen and stores it to HBITMAP (works fine), then fills BITMAPINFO struct and then creates a BYTE buffer from that struct, so I can send it via socket and then somehow (i still dont know how) recreate the bitmap using the BYTE buffer I created

    Code:
    				RECT rc;
    				GetClientRect(GetDesktopWindow(), &rc);
    
    				HDC hDC = GetDC(0);
    				HBITMAP hBmp = CreateCompatibleBitmap(hDC, rc.right, rc.bottom);
    
    				SelectObject(hDC, hBmp);
    
    				//Draws screenshot to the hBmp
    				BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    				BYTE* buf = new BYTE[256*256*256];
    				BITMAPINFO bmi;
    
    				int a = GetDIBits(hDC, hBmp, 0, rc.bottom, NULL, &bmi, DIB_RGB_COLORS);
    				if(a == 0)
    					MessageBox(hWnd, "Error when filling BMI", NULL, NULL);
    
    				int b = GetDIBits(hDC, hBmp, 0, rc.bottom, buf, &bmi, DIB_RGB_COLORS);
    				if(b == 0)
    					MessageBox(hWnd, "Error when filling buffer", NULL, NULL);
    				
    				//hBmp == screenshot
    
    				ReleaseDC(hWnd, hDC);
    				DeleteDC(hDC);
    				DeleteObject(hBmp);
    so the code is supposed to:

    1. get dimensions of screen
    2. create DC and compatible bitmap to store the screenshot
    3. draw screen to bitmap
    4. fill BITMAPINFO struct bmi with hBmp properties
    5. fill BYTE buffer buff with BITMAPINFO properties we got from point 4
    6. at this point, I should be able to send buffer, that contains everything needed to recreate bitmap (or?)
    7. free memory

    HOWEVER I'm getting "Error when filling BMI" error, and I have no idea why, also, how do I recreate bitmap from the "buf" after I get it from
    Code:
    GetDIBits(hDC, hBmp, 0, rc.bottom, buf, &bmi, DIB_RGB_COLORS);
    Last edited by DaigonoYouso; January 5th, 2014 at 12:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured