I'm working on a screen capture method for my program. For each screen capture, I'm trying to have the image named based on the DateTime down to the second. Right now, everything would be named screen.jpg.
How can I change "screen" to the current DateTime?
I've tried playing around with the line that names it, but I just keep getting errors such as "expression must have integral or unscoped enum type." I'm not sure what that means.
void BitmapToJpg(HBITMAP hbmpImage, int width, int height)
{
time_t now = time(0);
char* dt = ctime(&now);
Bitmap *p_bmp = Bitmap::FromHBITMAP(hbmpImage, NULL);
//Bitmap *p_bmp = new Bitmap(width, height, PixelFormat32bppARGB);
CLSID pngClsid;
int result = GetEncoderClsid(L"image/jpeg", &pngClsid);
if (result != -1)
std::cout << "Encoder succeeded" << std::endl;
else
std::cout << "Encoder failed" << std::endl;
p_bmp->Save(L"screen_.jpg", &pngClsid, NULL);
delete p_bmp;
}
UPDATE:
This version hasn't given me any errors, so I'm going to try to use it. I'll update this post to verify if it worked properly or not when my program attempts to use it! :)
Revised code:
void BitmapToJpg(HBITMAP hbmpImage, int width, int height)
{
time_t now = time(0);
char* dt = ctime(&now);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(dt);
Bitmap *p_bmp = Bitmap::FromHBITMAP(hbmpImage, NULL);
//Bitmap *p_bmp = new Bitmap(width, height, PixelFormat32bppARGB);
CLSID pngClsid;
int result = GetEncoderClsid(L"image/jpeg", &pngClsid);
if (result != -1)
std::cout << "Encoder succeeded" << std::endl;
else
std::cout << "Encoder failed" << std::endl;
std::wstring fileName = std::wstring(L"screen_") + wide + (L".jpg");
p_bmp->Save(fileName.c_str(), &pngClsid, NULL);
delete p_bmp;
}