Re: GDI+ screenshot save to JPG
Use wchar_t instead bcos your application is not a unicode application.
Code:
SYSTEMTIME SysTime;
GetLocalTime(&SysTime);
wchar_t filename[200];
memset(filename,0,sizeof(filename));
wsprintfW(filename,L"screen%02d:%02d:%02d h.jpeg",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
Re: GDI+ screenshot save to JPG
thx it compiles... but doesn't save screenshot to anywhere =\ without formatting it was saving it fine , maybe i used filename wrong? =\
full code
Code:
void gdiscreen()
{
SYSTEMTIME SysTime;
GetLocalTime(&SysTime);
wchar_t filename[200];
memset(filename,0,sizeof(filename));
wsprintfW(filename,L"C:\\screen%02d:%02d:%02d h.jpeg",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
HDC scrdc, memdc;
HBITMAP membit;
scrdc = ::GetDC(0);
int Height = GetSystemMetrics(SM_CYSCREEN);
int Width = GetSystemMetrics(SM_CXSCREEN);
memdc = CreateCompatibleDC(scrdc);
membit = CreateCompatibleBitmap(scrdc, Width, Height);
HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit);
BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
bitmap.Save(filename, &clsid);
SelectObject(memdc, hOldBitmap);
DeleteObject(memdc);
DeleteObject(membit);
::ReleaseDC(0,scrdc);
}
GdiplusShutdown(gdiplusToken);
}
Re: GDI+ screenshot save to JPG
You need to put the drive and folder path for the file path. If you are using Vista and is using UAC, your application do not have the permission to save to C drive. Use C drive and a folder in your file path.
Re: GDI+ screenshot save to JPG
but it was saving to C drive fine when i used only screen.jpg as a name, you sure about permissions?
Re: GDI+ screenshot save to JPG
Perhaps colon ":" is not valid for a file name.
Re: GDI+ screenshot save to JPG