EnBitmap.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[8/19/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __ENBITMAP_20160823__
  19. #define __ENBITMAP_20160823__
  20. #pragma once
  21. class CEnBitmap : public CBitmap
  22. {
  23. public:
  24. HBITMAP SetBitmap(HBITMAP hBitmap);
  25. CRect GetRect();
  26. void AlphaDisplay(CDC *pDC, BYTE bAlpha);
  27. CEnBitmap();
  28. virtual ~CEnBitmap();
  29. BOOL ExtendDraw(IN CDC *pDC, IN CRect rc, IN int nX, IN int nY, IN BOOL bTran = FALSE, IN UINT colorTransparent = RGB(255, 0, 255));
  30. BOOL ExtendDrawImage(OUT CEnBitmap &bmp, IN CRect rc, IN int nX, IN int nY);
  31. BOOL LoadImage(LPCTSTR szImagePath, COLORREF crBack = 0);
  32. BOOL LoadImage(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst = NULL, COLORREF crBack = 0);
  33. // helpers
  34. static HBITMAP LoadImageFile(LPCTSTR szImagePath, COLORREF crBack = 0);
  35. static HBITMAP LoadImageResource(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst = NULL, COLORREF crBack = 0);
  36. static BOOL GetResource(LPCTSTR lpName, LPCTSTR lpType, HMODULE hInst, void* pResource, int& nBufSize);
  37. static IPicture* LoadFromBuffer(BYTE* pBuff, int nSize);
  38. HRGN BitmapToRegion(COLORREF cTransparentColor = 0, COLORREF cTolerance = 0x101010);
  39. BOOL Draw(CDC *pDC, LPRECT r);
  40. BOOL DrawImage(CEnBitmap &bmp, int nX, int nY, int nCol, int nRow);
  41. void TransparentBlt(IN CDC &dc, IN CRect rc, IN UINT colorTransparent);
  42. int Width()
  43. {
  44. return GetWidth();
  45. }
  46. int GetWidth()
  47. {
  48. BITMAP bm;
  49. memset(&bm, 0, sizeof(bm));
  50. GetBitmap(&bm);
  51. return bm.bmWidth;
  52. }
  53. int Height()
  54. {
  55. return GetHeight();
  56. }
  57. int GetHeight()
  58. {
  59. BITMAP bm;
  60. memset(&bm, 0, sizeof(bm));
  61. GetBitmap(&bm);
  62. return bm.bmHeight;
  63. }
  64. int CEnBitmap::Grey(int r, int g, int b)
  65. {
  66. return (((b * 11) + (g * 59) + (r * 30)) / 100);
  67. }
  68. void DrawGreyScale(CDC *pDC);
  69. void DitherBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth,
  70. int nHeight, HBITMAP hbm, int nXSrc, int nYSrc);
  71. HPALETTE CreateReservedPalette(CDC *pDC);
  72. void FadeColorToGrayScale(CDC *pDC, int xDest, int yDest, int nLoops,
  73. int nDelay);
  74. HRGN InflateRegion(HRGN hRgn, int nXInflate, int nYInflate);
  75. HRGN CreateRegionExt(DWORD nCount, CONST RGNDATA *pRgnData);
  76. BOOL StretchDraw(CDC *pDC, LPRECT r, LPRECT sr);
  77. protected:
  78. static HBITMAP ExtractBitmap(IPicture* pPicture, COLORREF crBack);
  79. static int GetFileType(LPCTSTR szImagePath);
  80. };
  81. #endif // __ENBITMAP_20160823__