Browse Source

gdiplus

main
Hendrik Langer 6 years ago
parent
commit
1df0e16ce2
  1. BIN
      windows-snapshot-tool/bin/freeze.exe
  2. 37
      windows-snapshot-tool/src/main.cpp

BIN
windows-snapshot-tool/bin/freeze.exe

Binary file not shown.

37
windows-snapshot-tool/src/main.cpp

@ -21,6 +21,7 @@ void doScreenshot();
void InitNotifyIconData(); void InitNotifyIconData();
int CaptureImage(HWND hWnd, const wchar_t* filename); int CaptureImage(HWND hWnd, const wchar_t* filename);
void getRaspiStorage(LPWSTR out); void getRaspiStorage(LPWSTR out);
void SavePng(HBITMAP hBmp, LPCWSTR lpszFilename);
@ -254,6 +255,7 @@ void doScreenshot()
{ {
WCHAR path[12]; WCHAR path[12];
getRaspiStorage(path); getRaspiStorage(path);
MessageBox(Hwnd, path, L"Storage path", MB_OK);
CaptureImage(Hwnd, L"file.bmp"); CaptureImage(Hwnd, L"file.bmp");
} }
@ -299,7 +301,7 @@ void getRaspiStorage(LPWSTR out) {
if (GetVolumeInformationW(drive, volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, fileSystemName, ARRAYSIZE(fileSystemName))) if (GetVolumeInformationW(drive, volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, fileSystemName, ARRAYSIZE(fileSystemName)))
{ {
if (wcscmp(volumeName, L"SCREENSHOTS")) { if (wcscmp(volumeName, L"SCREENSHOTS")) {
wcsncpy(drive, out, sizeof(out)); wcsncpy(out, drive, sizeof(out));
} }
} }
} }
@ -405,6 +407,9 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) {
return -1; return -1;
} }
SavePng(hBmp, filename);
/*
// Get the BITMAP from the HBITMAP // Get the BITMAP from the HBITMAP
GetObject(hBmp,sizeof(BITMAP),&bmpScreen); GetObject(hBmp,sizeof(BITMAP),&bmpScreen);
@ -469,7 +474,7 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) {
//Close the handle for the file that was created //Close the handle for the file that was created
CloseHandle(hFile); CloseHandle(hFile);
*/
// clean up // clean up
DeleteObject(hbmScreen); DeleteObject(hbmScreen);
DeleteObject(hBmp); DeleteObject(hBmp);
@ -518,22 +523,38 @@ int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
* https://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows * https://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows
* https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-converting-a-bmp-image-to-a-png-image-use * https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-converting-a-bmp-image-to-a-png-image-use
*/ */
void SaveJpeg(HBITMAP hBmp, LPCWSTR lpszFilename, ULONG uQuality) void SavePng(HBITMAP hBmp, LPCWSTR lpszFilename)
{ {
//using namespace Gdiplus; using namespace Gdiplus;
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::GpBitmap* pBitmap; Gdiplus::GpBitmap* pBitmap;
Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap); Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap);
CLSID imageCLSID; CLSID imageCLSID;
GetEncoderClsid(L"image/jpeg", &imageCLSID); INT result;
result = GetEncoderClsid(L"image/png", &imageCLSID);
Gdiplus::EncoderParameters encoderParams; if (result < 0) {
MessageBox(Hwnd, L"The PNG encoder is not installed",L"Failed", MB_OK);
return;
}
/* Gdiplus::EncoderParameters encoderParams;
encoderParams.Count = 1; encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1; encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = Gdiplus::EncoderQuality; encoderParams.Parameter[0].Guid = Gdiplus::EncoderQuality;
encoderParams.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong; encoderParams.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &uQuality; encoderParams.Parameter[0].Value = &uQuality;*/
Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, lpszFilename, &imageCLSID, NULL);
DeleteObject(pBitmap);
Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, lpszFilename, &imageCLSID, &encoderParams); GdiplusShutdown(gdiplusToken);
} }

Loading…
Cancel
Save