Browse Source

import savejpeg example

main
Hendrik Langer 6 years ago
parent
commit
81fc529ef4
  1. 15
      windows-snapshot-tool/CMakeLists.txt
  2. BIN
      windows-snapshot-tool/bin/freeze.exe
  3. 64
      windows-snapshot-tool/cmake/FindGDIPLUS.cmake
  4. 60
      windows-snapshot-tool/src/main.cpp

15
windows-snapshot-tool/CMakeLists.txt

@ -1,6 +1,7 @@
cmake_minimum_required (VERSION 2.4)
project (freeze)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
@ -8,10 +9,22 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
add_definitions(-DUNICODE -D_UNICODE)
SET( CMAKE_EXE_LINKER_FLAGS "-mwindows" )
include_directories("${PROJECT_SOURCE_DIR}")
find_package( GDIPLUS )
set(CMAKE_REQUIRED_DEFINITIONS -DGDIPLUS_LOWERCASE=${GDIPLUS_LOWERCASE})
set(CMAKE_REQUIRED_INCLUDES ${GDIPLUS_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${GDIPLUS_LIBRARY})
#find_library(GDIPLUS gdiplus)
#add_library(gdiplus SHARED)
add_definitions(${GDIPLUS_DEFINITIONS})
link_directories(${GDIPLUS_INCLUDE_DIR})
link_libraries(${GDIPLUS_LIBRARIES})
include_directories("${PROJECT_SOURCE_DIR} ${GDIPLUS_INCLUDE_DIR}")
add_executable (freeze src/main.cpp src/resource.rc)
target_link_libraries(freeze ${GDIPLUS})
# mkdir build && cd build # rm -r CMakeCache.txt CMakeFiles/
# cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-cross-mingw32-linux.cmake ../

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

Binary file not shown.

64
windows-snapshot-tool/cmake/FindGDIPLUS.cmake

@ -0,0 +1,64 @@
# - Find GDI+
# Find the GDI+ includes and libraries
#
# GDIPLUS_INCLUDE_DIR - where to find gdiplus.h
# GDIPLUS_LIBRARIES - List of libraries when using GDI+.
# GDIPLUS_FOUND - True if GDI+ found.
if(GDIPLUS_INCLUDE_DIR)
# Already in cache, be silent
set(GDIPLUS_FIND_QUIETLY TRUE)
endif(GDIPLUS_INCLUDE_DIR)
macro(check_winsdk_root_dir key)
get_filename_component(CANDIDATE ${key} ABSOLUTE)
if (EXISTS ${CANDIDATE})
set(WINSDK_ROOT_DIR ${CANDIDATE})
endif()
endmacro()
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Microsoft SDKs\\\\Windows\\\\v7.0;InstallationFolder]")
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Microsoft SDKs\\\\Windows\\\\v7.0A;InstallationFolder]")
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Microsoft SDKs\\\\Windows\\\\v7.1;InstallationFolder]")
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Microsoft SDKs\\\\Windows\\\\v7.1A;InstallationFolder]")
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Windows Kits\\\\Installed Roots;KitsRoot]")
check_winsdk_root_dir("[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Windows Kits\\\\Installed Roots;KitsRoot81]")
find_path(GDIPLUS_INCLUDE_DIR
NAMES
GdiPlus.h
gdiplus.h
PATH_SUFFIXES
Include
Include/um
Include/shared
PATHS
"${WINSDK_ROOT_DIR}"
)
if(EXISTS ${GDIPLUS_INCLUDE_DIR}/GdiPlus.h)
set(GDIPLUS_LOWERCASE 0 CACHE INTERNAL "Is GdiPlus.h spelt with lowercase?")
else()
set(GDIPLUS_LOWERCASE 1 CACHE INTERNAL "Is GdiPlus.h spelt with lowercase?")
endif()
if (MINGW)
find_library(GDIPLUS_LIBRARY NAMES libgdiplus gdiplus)
else(MINGW)
set(GDIPLUS_LIBRARY gdiplus)
endif(MINGW)
# Handle the QUIETLY and REQUIRED arguments and set GDIPLUS_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GDIPLUS DEFAULT_MSG
GDIPLUS_INCLUDE_DIR GDIPLUS_LIBRARY)
if(GDIPLUS_FOUND)
set(GDIPLUS_LIBRARIES ${GDIPLUS_LIBRARY})
else(GDIPLUS_FOUND)
set(GDIPLUS_LIBRARIES)
endif(GDIPLUS_FOUND)
mark_as_advanced(GDIPLUS_INCLUDE_DIR GDIPLUS_LIBRARY GDIPLUS_LOWERCASE)

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

@ -1,5 +1,7 @@
#include "resource.h"
#include "LimitSingleInstance.h"
#include <gdiplus.h>
//#include "LimitSingleInstance.h"
/*variables*/
UINT WM_TASKBAR = 0;
@ -478,3 +480,59 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) {
return 0;
}
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
using namespace Gdiplus;
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
/** Save compressed picture
*
* https://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows
*/
void SaveJpeg(HBITMAP hBmp, LPCWSTR lpszFilename, ULONG uQuality)
{
//using namespace Gdiplus;
Gdiplus::GpBitmap* pBitmap;
Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap);
CLSID imageCLSID;
GetEncoderClsid(L"image/jpeg", &imageCLSID);
Gdiplus::EncoderParameters encoderParams;
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = Gdiplus::EncoderQuality;
encoderParams.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &uQuality;
Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, lpszFilename, &imageCLSID, &encoderParams);
}

Loading…
Cancel
Save