#ifndef __IMG_COMMON_20151214__ #define __IMG_COMMON_20151214__ #pragma once #include #include using namespace std; #include using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") #ifndef _UNICODE typedef string TString; #else typedef wstring TString; #endif enum ZOOMTYPE// 缩放结果; { ZoomNull = 0, // 无缩放; ZoomIn = 1, // 缩小; ZoomOut = 2 // 放大; }; // 磁盘状态; enum DISKSTATUS { DISK_NULL = -1, // 硬盘或目录不存在; DISK_NORMAL = 0, // 硬盘或目录正常; DISK_DAMAGED = 1, // 硬盘损坏; DISK_OUTOFCAPACITY = 2 // 硬盘容量不足; }; #define GET_XPIX(x) ( x >> 16) // 高16位; #define GET_YPIX(y) (y & 0x0000ffff) // 低16位; #define SET_PIX(x,y) (( x << 16) | y) // 高低合并; #define INVALID_COPY_PIX ((DWORD)-1) // 传递此值,表示没有复制压缩; class IMGCommon { public: IMGCommon(void); ~IMGCommon(void); static ULONG_PTR m_gdiplusToken; public: ////////////////////////////////////////////////////////////////////////// static BOOL LoadImgFromFile(IN Image** pImg, LPCTSTR lpPath, IN BOOL useEmbeddedColorManagement = FALSE); static BOOL LoadImgFromBuffer(IN Image** pImg, IN BYTE* pBuffer, IN CONST INT& nBufLen); static BOOL LoadImgFromBuffer(IN Image** pImg, LPCTSTR lpPath, IN BOOL useEmbeddedColorManagement = FALSE); static Image* LoadImgFromResource( IN HMODULE hModule, IN LPCTSTR lpName, IN LPCTSTR lpType); ////////////////////////////////////////////////////////////////////////// static BOOL GetOrientation(IN Image *pImg); static int GetEncoderClsid(IN CONST WCHAR* format, OUT CLSID* pClsid); static BOOL SaveImg2newfile(IN Image* pImg, IN CString strNewfile, IN ULONG uQuality); static BOOL SaveImg2newfile(IN Image* pImg, IN TString strNewfile, IN ULONG uQuality); static int ZoomImg(IN CRect &Imgrc, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix); static int ZoomImg(IN CONST DWORD &dwImgPix, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix); static BOOL ImgThumbnail(IN Image* pImg, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality); static BOOL ImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE); static BOOL ImgThumbnail(IN CONST TString &strImgpath, IN CONST DWORD &dwDisplayPix, IN TString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE); static BOOL SimpleImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE); #ifdef _WATER_MARK_ // 给指定的图片加图片水印(位置、大小暂不支持); static Image* AppendImgWatermark(IN Image* pImg, IN Image* pWatemarkImg); static Image* AppendImgWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkImgpath); static Image* AppendImgWatermark(IN LPCTSTR lpImgpath, IN Image* pWatemarkImg); static Image* AppendImgWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkImgpath); static BOOL AppendImgWatermark(IN Image* pImg, IN Image* pWatemarkImg, IN LPCTSTR lpSaveImgpath); static BOOL AppendImgWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkImgpath, IN LPCTSTR lpSaveImgpath); static BOOL AppendImgWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkImgpath, IN LPCTSTR lpSaveImgpath); // 给指定图片加文字水印(位置、字体、颜色暂不支持); static Image* AppendWordWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkString); static Image* AppendWordWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkString); static BOOL SaveBitmap(IN CDC *pDC, IN CBitmap* pBitmap, IN CONST INT& nBitdepth, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath); static BOOL SaveBitmapEx(IN CDC *pDC, IN CBitmap* pBitmap, IN CONST INT& nBitdepth, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath); static void DrawString(IN CDC* pdc, IN CONST INT& nFontSize, IN LPCTSTR lpFontName, IN LPCTSTR lpString, IN OUT CRect &rcString); ////////////////////////////////////////////////////////////////////////// #endif // 获取文件的图标; static HICON GetFileIcon(IN const CString& strFilePath, IN BOOL bLarge); }; #endif