IMGCommon.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef __IMG_COMMON_20151214__
  2. #define __IMG_COMMON_20151214__
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7. #include <gdiplus.h>
  8. using namespace Gdiplus;
  9. #pragma comment(lib, "gdiplus.lib")
  10. #ifndef _UNICODE
  11. typedef string TString;
  12. #else
  13. typedef wstring TString;
  14. #endif
  15. enum ZOOMTYPE// 缩放结果;
  16. {
  17. ZoomNull = 0, // 无缩放;
  18. ZoomIn = 1, // 缩小;
  19. ZoomOut = 2 // 放大;
  20. };
  21. // 磁盘状态;
  22. enum DISKSTATUS
  23. {
  24. DISK_NULL = -1, // 硬盘或目录不存在;
  25. DISK_NORMAL = 0, // 硬盘或目录正常;
  26. DISK_DAMAGED = 1, // 硬盘损坏;
  27. DISK_OUTOFCAPACITY = 2 // 硬盘容量不足;
  28. };
  29. #define GET_XPIX(x) ( x >> 16) // 高16位;
  30. #define GET_YPIX(y) (y & 0x0000ffff) // 低16位;
  31. #define SET_PIX(x,y) (( x << 16) | y) // 高低合并;
  32. #define INVALID_COPY_PIX ((DWORD)-1) // 传递此值,表示没有复制压缩;
  33. class IMGCommon
  34. {
  35. public:
  36. IMGCommon(void);
  37. ~IMGCommon(void);
  38. static ULONG_PTR m_gdiplusToken;
  39. public:
  40. //////////////////////////////////////////////////////////////////////////
  41. static BOOL LoadImgFromFile(IN Image** pImg, LPCTSTR lpPath, IN BOOL useEmbeddedColorManagement = FALSE);
  42. static BOOL LoadImgFromBuffer(IN Image** pImg, IN BYTE* pBuffer, IN CONST INT& nBufLen);
  43. static BOOL LoadImgFromBuffer(IN Image** pImg, LPCTSTR lpPath, IN BOOL useEmbeddedColorManagement = FALSE);
  44. static Image* LoadImgFromResource( IN HMODULE hModule, IN LPCTSTR lpName, IN LPCTSTR lpType);
  45. //////////////////////////////////////////////////////////////////////////
  46. static BOOL GetOrientation(IN Image *pImg);
  47. static int GetEncoderClsid(IN CONST WCHAR* format, OUT CLSID* pClsid);
  48. static BOOL SaveImg2newfile(IN Image* pImg, IN CString strNewfile, IN ULONG uQuality);
  49. static BOOL SaveImg2newfile(IN Image* pImg, IN TString strNewfile, IN ULONG uQuality);
  50. static int ZoomImg(IN CRect &Imgrc, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix);
  51. static int ZoomImg(IN CONST DWORD &dwImgPix, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix);
  52. static BOOL ImgThumbnail(IN Image* pImg, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality);
  53. static BOOL ImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE);
  54. static BOOL ImgThumbnail(IN CONST TString &strImgpath, IN CONST DWORD &dwDisplayPix, IN TString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE);
  55. static BOOL SimpleImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality, IN BOOL useEmbeddedColorManagement = FALSE);
  56. #ifdef _WATER_MARK_
  57. // 给指定的图片加图片水印(位置、大小暂不支持);
  58. static Image* AppendImgWatermark(IN Image* pImg, IN Image* pWatemarkImg);
  59. static Image* AppendImgWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkImgpath);
  60. static Image* AppendImgWatermark(IN LPCTSTR lpImgpath, IN Image* pWatemarkImg);
  61. static Image* AppendImgWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkImgpath);
  62. static BOOL AppendImgWatermark(IN Image* pImg, IN Image* pWatemarkImg, IN LPCTSTR lpSaveImgpath);
  63. static BOOL AppendImgWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkImgpath, IN LPCTSTR lpSaveImgpath);
  64. static BOOL AppendImgWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkImgpath, IN LPCTSTR lpSaveImgpath);
  65. // 给指定图片加文字水印(位置、字体、颜色暂不支持);
  66. static Image* AppendWordWatermark(IN Image* pImg, IN LPCTSTR lpWatemarkString);
  67. static Image* AppendWordWatermark(IN LPCTSTR lpImgpath, IN LPCTSTR lpWatemarkString);
  68. static BOOL SaveBitmap(IN CDC *pDC, IN CBitmap* pBitmap, IN CONST INT& nBitdepth, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath);
  69. static BOOL SaveBitmapEx(IN CDC *pDC, IN CBitmap* pBitmap, IN CONST INT& nBitdepth, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath);
  70. static void DrawString(IN CDC* pdc, IN CONST INT& nFontSize, IN LPCTSTR lpFontName, IN LPCTSTR lpString, IN OUT CRect &rcString);
  71. //////////////////////////////////////////////////////////////////////////
  72. #endif
  73. // 获取文件的图标;
  74. static HICON GetFileIcon(IN const CString& strFilePath, IN BOOL bLarge);
  75. };
  76. #endif