D
D
DoubleTree2021-11-03 18:34:49
C++ / C#
DoubleTree, 2021-11-03 18:34:49

Bitmap.Save() - not working, c++, what to do?

I'm trying to save a Png to disk, but for some reason it doesn't save.
I saved the image to the buffer and everything was fine, the picture really was what it needed.
But I can’t save it to disk, there is no error, just like the result.

#include <windows.h>

#include <gdiplus.h>
#pragma comment(lib, "GdiPlus.lib")

void screenShot()
{
    const int xCordStart = GetSystemMetrics(SM_XVIRTUALSCREEN);
    const int yCordStart = GetSystemMetrics(SM_YVIRTUALSCREEN);
    const int xCordFinish = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    const int yCordFinish = GetSystemMetrics(SM_CYVIRTUALSCREEN);

    const int width = 500;
    const int height = 500;

    HDC hScreen = GetDC(0);
    HDC hDc = CreateCompatibleDC(hScreen);
    HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, width, height);
    HGDIOBJ old_obj = SelectObject(hDc, hBitmap);
    BOOL bRet = BitBlt(hDc, 0, 0, width, height, hScreen, 0, 0, SRCCOPY);

    Gdiplus::Bitmap bitmap(hBitmap, NULL);
    const GUID png{ 0x557cf406, 0x1a04, 0x11d3, {0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} };
    bitmap.Save(L"C:/save.png", &png);
    DeleteObject(hBitmap);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Limons, 2021-11-04
@Limons

It's not entirely clear yet, more precisely, what is it actually for:
Gdiplus::Bitmap bitmap(hBitmap, NULL);
And it's not clear:
Why HGDIOBJ old_obj = SelectObject(hDc, hBitmap);
Not SelectObject(hDc, hBitmap);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question