Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question