T
T
tigmen2022-01-28 23:51:14
C++ / C#
tigmen, 2022-01-28 23:51:14

Bitmap.Save(L"g.png", &png); does not work. Why?

I use it to save a screenshot. The file is simply not saved (no error output).bitmap.Save(L"g.png", &png)

int getmx(HWND hwnd)
{
    int x, x1;
    x = GetSystemMetrics(SM_XVIRTUALSCREEN);
    x1 = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    return x1 - x;
}
int getmy(HWND hwnd)
{
    int y, y1;
    y = GetSystemMetrics(SM_YVIRTUALSCREEN);
    y1 = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    return y1 - y;
}
int screenshot(HWND hwnd)
{
    int w, h;
    w = getmx(hwnd);
    h = getmy(hwnd);

    HDC hScreen = GetDC(NULL);
    
    HDC hdc = CreateCompatibleDC(hScreen);
    HBITMAP hbitmap = CreateCompatibleBitmap(hScreen, w, h);
    HGDIOBJ old_obj = SelectObject(hdc, hbitmap);
    BOOL bRet = BitBlt(hdc, 0, 0, w, h, hScreen, GetSystemMetrics(SM_XVIRTUALSCREEN),
    GetSystemMetrics(SM_YVIRTUALSCREEN), SRCCOPY);
    Gdiplus::Bitmap bitmap(hbitmap, NULL);
    CLSID clsid;
    const GUID png{ 0x557cf406, 0x1a04, 0x11d3, {0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} };
    bitmap.Save(L"g.png", &png);
    ReleaseDC(NULL, hdc);
    DeleteObject(hbitmap);
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-01-29
@wataru

Does it compile at all? Save seems to take 3 parameters. It is possible to transfer NULL there.
Check that Save returns something. It will not write an error anywhere - it is waiting for you to look at the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question