TSFindPicture.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ////////////////////////////////////////////////////////////////////////////////////
  2. #if !defined(MYFINDPICTURECLASS_H)
  3. #define MYFINDPICTURECLASS_H
  4. #include <windows.h>
  5. #include "d3d9.h"
  6. #include <GdiPlus.h>
  7. #include <GdiplusBitmap.h>
  8. #include <vector>
  9. class MyFindPictureClass
  10. {
  11. public:
  12. MyFindPictureClass(void);
  13. ~MyFindPictureClass(void);
  14. enum RUNTYPE { TurnUP = 0, TurnDOWN, TurnLEFT, TurnRIGHT, TurnERRORR };
  15. //LPDIRECT3DDEVICE9 m_pDxdevice;
  16. //HWND m_Wnd;
  17. bool isprocessColor;//说明是找色或者取色
  18. int loadWidth;
  19. int loadHeight;
  20. HWND m_parenthwnd;
  21. HBITMAP hDXBitmap;
  22. HDC hDXMemDC;
  23. HWND m_hwnd;
  24. DWORD m_displayMode;//图色模式
  25. bool IsLastFindStr;//是否最后一次查找
  26. //COLORREF pWndBmpBuffer[2000][2000];
  27. COLORREF** pWndBmpBuffer;
  28. //DWORD ColorDataInfo[2000][2000];
  29. BYTE* pBuffer;
  30. //COLORREF** pColorBuffer;
  31. int wndWidth;
  32. int wndHeight;
  33. int nbuffersize;
  34. PVOID pbuffer;
  35. bool SaveGDIBitmap(HWND hWnd, RECT rect, wchar_t* savepath);
  36. bool SaveBitmapToFile(HBITMAP hBitmap, LPCWSTR lpFileName);
  37. bool CopyScreenToBitmap(LPRECT lpRect, wchar_t* savepath);
  38. DWORD GetBkMouseShape(HCURSOR bkmouseshape = NULL);//默认bkmouseshape为空时为前台模式, bkmouseshape有值的时候是后台模式
  39. bool loadBitmap(wchar_t* path);
  40. //////////////////找图 支持的是24位位图/////////////////////
  41. //// 图片格式错误或者没找到图片,函数返回-1
  42. //// 参数 说明
  43. //// hwnd 窗口的句柄,为NULL表示前台查找,不为NULL表示后台查找
  44. //// left 左上角x
  45. //// top 左上角y
  46. //// right 右下角x
  47. //// bottom 右下角y
  48. //// path 图片的路径,支持多张图片,使用"|"隔开
  49. //// colorOffset 色偏 例如"102030"
  50. //// simi 相似度
  51. //// dir 检索方式
  52. //// xpos 返回的图片的左上角x坐标
  53. //// ypos 返回的图片的左上角y坐标
  54. int findPicture(PVOID pbuffer, HWND hwnd, int left, int top, int right, int bottom, wchar_t* path, wchar_t* color, double simi, int dir, long& x, long& y, DWORD(*ColorDataInfo)[2000], wchar_t* retstring = NULL, int type = 0);
  55. /////// 颜色内存处理。。 提高速度 //////////////////////
  56. bool processCreenWindow(int color, int left, int top, int right, int bottom, double simi, int dir, int& x, int& y, wchar_t* colorStr = NULL, bool isMulitColor = false);
  57. /////// 后台颜色内存处理。。 提高速度 //////////////////////
  58. int processColor(PVOID pbuffer, HWND hwnd, int& color, int left, int top, int right, int buttom, double simi, int dir, long& x, long& y, DWORD(*ColorDataInfo)[2000], wchar_t* colorstr = NULL, wchar_t* retstring = NULL, wchar_t* MultiColor = NULL);
  59. //将BMP图转JPG图
  60. bool BMP2JPG(wchar_t* strBMPFile, wchar_t* strJPGFile);
  61. //将BMP图转PNG图
  62. bool BMP2PNG(wchar_t* strBMPFile, wchar_t* strPNGFile);
  63. //////////////////////////////////////////////////////////////////////////////////////找字算法
  64. int strColor;//字的颜色
  65. int strColors[MAX_PATH];//字的颜色
  66. int strColoroff[MAX_PATH];//字的色偏
  67. int ncount;//记录位图加载的点阵个数
  68. int addrxy[MAX_PATH * 10][4];
  69. int dictindex;//记录当前字库的数量
  70. int usingindex; //当前使用字库的下标
  71. std::vector<POINT> pWndBmpStr[2048];
  72. short** pWndBmpStrxy;//存储当前图片的所有坐标对于的整形值
  73. wchar_t SetPath[MAX_PATH];
  74. //wchar_t SetPicPwdString[MAX_PATH];
  75. //COLORREF **pLoadstrBuffer;
  76. //COLORREF pLoadstrBuffer[11][MAX_PATH-10];
  77. void hextobyte(char* hexStr, char* byteStr);//将十六进制字符串转换成二进制字符串
  78. //void byteTopic(short strvalue[MAX_PATH],int strwide,COLORREF pLoadstrBuffer[11][MAX_PATH-10]);//二进制数值还原成图片MAX_PATH
  79. void byteTopic(short strvalue[MAX_PATH], int strwide);//二进制数值还原成图片MAX_PATH
  80. //bool comparaStrTosim(COLORREF pLoadstrBuffer[11][MAX_PATH-10],int strwide,int strhight,int &RetX,int &RetY,int startX,int startY,float simi,int nstrcount); //相似度匹配
  81. bool comparaStrTosim(int strwide, int strhight, int& RetX, int& RetY, int startX, int startY, float simi, int nstrcount); //相似度匹配
  82. bool comparaStr(short pLoadstrBufferxy[MAX_PATH], int strwide, int strhight, int& RetX, int& RetY, int startX, int startY, float simi, int nstrcount);//匹配字符串
  83. void dicthextobyte(char* hexStr, char* byteStr, int& hexlen, short& nstrinfo);// 字库信息转二进制
  84. bool GetStringInfo();//获取位置点阵信息
  85. //获取位置点阵信息,和GetStringInfo区别是,多了一层X坐标的扫描,排除多余无效的点阵信息
  86. bool GetStringInfo1();
  87. bool MySetDict(int nindex, wchar_t* dictpath, pMyDictInfo* MyDictCount, int* nMyDictCountsize, int& NowUsingDictIndex);//设置字库 加载字库
  88. bool MyUseDict(int Useindex, pMyDictInfo* MyDictCount, int& NowUsingDictIndex); //使用字库
  89. bool MyDeleteDict(int deleteindex, pMyDictInfo* MyDictCount, int* nMyDictCountsize, int& NowUsingDictIndex); //删除字库
  90. int ocr(PVOID pbuffer, HWND hwnd, int left, int top, int right, int bottom, wchar_t* color_format, double simi, wchar_t* retstr, pMyDictInfo* MyDictCount, int* nMyDictCountsize, int NowUsingDictIndex, DWORD(*ColorDataInfo)[2000], int type = 0);
  91. int FindStr(PVOID pbuffer, HWND hwnd, int left, int top, int right, int bottom, wchar_t* strings, wchar_t* color, double simi, long& x, long& y, pMyDictInfo* MyDictCount, int* nMyDictCountsize, int NowUsingDictIndex, DWORD(*ColorDataInfo)[2000], wchar_t* retstring = NULL, int type = 0);
  92. int FindStrFast(PVOID pbuffer, HWND hwnd, int left, int top, int right, int bottom, wchar_t* strings, wchar_t* color, double simi, long& x, long& y, pMyDictInfo* MyDictCount, int* nMyDictCountsize, int NowUsingDictIndex, DWORD(*ColorDataInfo)[2000], wchar_t* retstring = NULL, int type = 0);
  93. //pMyDictInfo mydict;
  94. //////////////////////////////////////////////////////////////////////////////////////找字算法
  95. private:
  96. bool IsFindPicNext;
  97. COLORREF** pLoadBmpBuffer;
  98. //COLORREF** pWndBmpBuffer;
  99. int ncolors; //色偏个数
  100. BYTE m_colorOffsR; // R的偏移量
  101. BYTE m_colorOffsG; // G的偏移量
  102. BYTE m_colorOffsB; // B的偏移量
  103. BYTE m_colorOffR[MAX_PATH]; // R的偏移量
  104. BYTE m_colorOffG[MAX_PATH]; // G的偏移量
  105. BYTE m_colorOffB[MAX_PATH]; // B的偏移量
  106. /*double m_sim; // 相似度*/ //未使用该变量
  107. int m_Dir; // 检索方式
  108. int m_simColor; // 相似度的颜色边界值
  109. //////////////////////////////存储传进来的四点的范围/////////////
  110. int m_Left; // 左上点
  111. int m_Top; // 顶端点
  112. int m_Right; // 右下点
  113. int m_bottom; // 底端点
  114. int xpos_offset;
  115. int ypos_offset;
  116. ///////////////////////////// 助记透明图的处理 /////////////
  117. int m_helpXpoint;
  118. int m_helpYpoint;
  119. //bool catchWindowBitmap();
  120. //bool processBKWindows(HWND src_hWnd);
  121. //配合BMP2JPG使用
  122. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
  123. bool getGDIBitmap(HWND wnd, RECT rc, int typemode = 0);//初始默认为找图 ,typemode=0
  124. bool getDXBitmap(PVOID pbuffer, DWORD(*ColorDataInfo)[2000], int typemode = 0);//初始默认为找图 ,typemode=0
  125. bool findImage(wchar_t* path, long& x, long& y, int type = 0);
  126. bool comparabmp(int startX, int startY, int endX, int endY);
  127. //////////////// 检索 方式 //////////////////
  128. //////////////////////////////////0:从左到右,从上倒下/////////////////////
  129. bool leftToRightFromTop(long& x, long& y);
  130. //////处理背景色为透明的图片////////////////
  131. bool comparaLeftToRightFromTop(int h, int w, int startX, int startY);
  132. //////处理背景色为不透明的图片////////////////
  133. bool comparaLeftToRightFromTopEx(int h, int w);
  134. ////////////////////////////////////1:从左到右,从下倒上//////////////////
  135. bool leftToRightFromBottom(long& x, long& y);
  136. ////////处理背景色为透明的图片////////////////
  137. bool comparaLeftToRightFromBottom(int h, int w, int startX, int startY);
  138. ////////处理背景色为不透明的图片////////////////
  139. bool comparaLeftToRightFromBottomEx(int h, int w);
  140. ////////////////////////////////////2:从右到左,从上倒下//////////////////
  141. bool rightToLeftFromTop(long& x, long& y);
  142. ////////处理背景色为透明的图片////////////////
  143. bool comparaRightToLeftFromTop(int h, int w, int startX, int startY);
  144. ////////处理背景色为不透明的图片////////////////
  145. bool comparaRightToLeftFromTopEx(int h, int w);
  146. //////////////////////////////////3:从右到左,从下倒上///////////////////
  147. bool rightToLeftFromBottom(long& x, long& y);
  148. ////////处理背景色为透明的图片////////////////
  149. bool comparaRightToLeftFromBottom(int h, int w, int startX, int startY);
  150. ////////处理背景色为不透明的图片////////////////
  151. bool comparaRightToLeftFromBottomEx(int h, int w);
  152. COLORREF RgbToBgb(__in COLORREF rgb);
  153. bool FindMultiColor(wchar_t* MultiColor, int i, int j, int Bottom, int right, int help_simi);
  154. };
  155. #endif