Screen Capture, decrease bitmap file size

Asked

Viewed 102 times

1

One of the functions of the project that I am working makes the capture of the user screen, however the bitmap file is getting too big, from 6MB to 8MB, It is bad to be able to send via socket or future make a stream per frame, Could anyone help me in how I can decrease the size of this file? I’ll be posting the code I’m using to capture the screen, and then save it to a file..

    void Remote_Manip::CaptureScreen(Socket_Setup &socket_setup)
{
    int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
    int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
    HWND hDesktopWnd = GetDesktopWindow();
    HDC hDesktopDC = GetDC(hDesktopWnd);
    HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
    HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC,
        nScreenWidth, nScreenHeight);
    SelectObject(hCaptureDC, hCaptureBitmap);
    BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight,
        hDesktopDC, 0, 0, SRCCOPY | CAPTUREBLT);

    WCHAR path[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path)))
    {
        std::wstring directory_create = path;
        std::string DEFAULT_DIR;

        DEFAULT_DIR.append(directory_create.begin(), directory_create.end());
        DEFAULT_DIR.append("\\Pictures");
        DEFAULT_DIR.append("\\image.bmp");

        LPCSTR fname = DEFAULT_DIR.c_str();
        HPALETTE hpal = NULL;
        saveBitmap(fname, hCaptureBitmap, hpal);

        ReleaseDC(hDesktopWnd, hDesktopDC);
        DeleteDC(hCaptureDC);
        DeleteObject(hCaptureBitmap);

        // fução para enviar a imagem via socket.
        FILE_DOWNLOAD(DEFAULT_DIR.c_str(), socket_setup);
    }
}
  • 1

    The clear solution would be to save in PNG format.

  • A bitmap file will actually get large, proportionally to the resolution at which its interface is being displayed, as it stores the "raw data" (raw) of each pixel. Using a compression format, as suggested by @Guilhermebernal, can be interesting to decrease this size in storage.

  • 1

    Now, another important issue that you yourself envision is future use. Since you mention the transmission to streaming, it is good to think about sending only the difference between each frame (frame). In the end, the problem will be the same as the other question: http://answall.com/questions/6978/howto determinar-o-menor-n%C3%Small Bamero-de-small-%C3%A1reas-para-render

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.