日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

高仿大漠找字FindStr

發(fā)布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 高仿大漠找字FindStr 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

C++高仿大漠找字FindStr

字庫就用大漠字庫就可以了。
大家先來看看效果圖:
砸門先制作一個這樣的字庫:

上面就是我定義的方字!當然了隨你高興寫成什么字都可以。
但是最高不能超過256個字節(jié)
效果圖如下:

看下調用方法
首先申請一個程序集變量:
TKdmsoft dm;//天空大漠
dm.SetPath(“d:\”);//設置操作的磁盤地址
dm.SetDict(“找字.txt”);//設置字庫

int x=-1, y=-1;//申請兩個返回的地址 //time_t t; time(&t); //tm* m=localtime(&t); // //int sbb= m->tm_sec; dm.FindStr(0, 1, 215, 113, "方方", "ff0000-050505", x, y);//調用方法 if (x>=0) {str.Format("%d", x);SetDlgItemText(EDIT_x, str);str.Format("%d", y);SetDlgItemText(EDIT_y, str); } 下面是找字類: FindstrEx.h #pragma oncestruct MyDict {char* Dict; //要操作字體的點陣char Neam[256] = {0}; //要操作的字符名稱int yxxs;//有效像數(shù)int spxs;//豎排行數(shù) };struct MyDictwh {int w;//字體寬度int h;//字體高度 }; class TKdmsoft { public:TKdmsoft();TKdmsoft(HWND hnd);~TKdmsoft();public:int FindStr(int x1, int y1, int x2, int y2, const char* str, const char* color_format, int& X, int& Y);long SetDict(char* file);long SetPath(char* path);long Sethwnd(HWND hwnd);long CloseTk();//釋放插件long GetZtSize();//獲取尋找的文字個數(shù)private:int GetDict(int dex, const char* str_a);//解析大漠字庫char* GetDictWh(const char* str, int& W, int& h, int& uto); //取回字符寬高 private:char* strpath=NULL;//操作默認磁盤MyDict* Dict=NULL;//字庫文件MyDictwh* dictwh; //當次字體大小int DictSize = 0; //字庫大小或有多少個字HWND g_hwnd; //需要操作的窗口句柄int ZTsize = 0; //字體大小}; inline long TKdmsoft::CloseTk() {for (size_t i = 0; i < DictSize; i++){delete[] Dict[i].Dict;}delete[] Dict;delete[] strpath;return 0; }long TKdmsoft::GetZtSize()//返回字體個數(shù) {if (ZTsize==0){return 0;}return ZTsize; }// 天空插件TKdmsoft::TKdmsoft(HWND hnd ) {g_hwnd = hnd; }TKdmsoft::~TKdmsoft() { } inline TKdmsoft::TKdmsoft() { }long TKdmsoft::Sethwnd(HWND hwnd) {if (hwnd==0){return -1;}g_hwnd = hwnd;return 0; }//取兩個十進制數(shù)的差,返回:十六進制文本 CString QCZ(int p1, int p2) {CString str;str = IntToHex(abs(p1 - p2));if (str.GetLength() == 2){return str;}if (str.GetLength() == 1){return "0" + str;}if (str.GetLength() == 0){return "00";}return ""; }//取色差 int QSC(CString str, int& c1, int& c2) {int strl = str.GetLength();CString CR, CP, str1;int strlock = 0;for (size_t i = 0; i < strl; i++){str1 = "";str1 = str.Mid(i, 1);if (str1 != "-"){if (!((str1[0] >= '0' && str1[0] <= '9') || (str1[0] >= 'a' && str1[0] <= 'f') || (str1[0] >= 'A' && str1[0] <= 'F'))){c1 = -1; return -1;}//取反就是找不到上面的就返回一個錯誤碼}if (str1 == "-") { strlock = 1; }//控制分離偏色和顏色的開關if (strlock == 0){CR += str1;}if (strlock == 1 && str1 != "-"){CP += str1;}}CString strt;strt.Format("%s%s%s", CR.Mid(4, 2), CR.Mid(2, 2), CR.Mid(0, 2));c1 = Hex_Conversion_Dec(strt);//進制十六倒十strt.Format("%s%s%s", CP.Mid(4, 2), CP.Mid(2, 2), CP.Mid(0, 2));c2 = Hex_Conversion_Dec(strt);return 0; } //圖片相似度 int redToGreen(COLORREF& c, int c1, int c2)//把圖片二值化 {//int R = c;// GetRValue(c);//獲取c中R的值CString str;int b, d;int R, G, B;R = GetRValue(c);//獲取c中R的值G = GetGValue(c);//獲取c中R的值B = GetBValue(c);//獲取c中R的值int r1, g1, b1, pr, pg, pb;r1 = GetRValue(c1);//獲取c中R的值g1 = GetGValue(c1);//獲取c中R的值b1 = GetBValue(c1);//獲取c中R的值pr = GetRValue(c2);//獲取c中R的值pg = GetGValue(c2);//獲取c中R的值pb = GetBValue(c2);//獲取c中R的值{if (pr >= 1){b = r1;r1 += pr;//最大偏移pr = b - pr;//最小偏移if (r1 > 255) {r1 = 255;//控制數(shù)據(jù)溢出}else if (r1 < 0) {r1 = 0;//控制數(shù)據(jù)溢出}if (pr > 255){pr = 255;//控制數(shù)據(jù)溢出}else if (pr < 0) {pr = 0;//控制數(shù)據(jù)溢出}if (R > r1 || R < pr){return 0;}}else if (pr == 0){if (R != r1){return 0;}}}{if (pg >= 1){if (pg >= 1){b = g1;g1 += pg;//最大偏移pg = b - pg;//最小偏移if (g1 > 255) {g1 = 255;//控制數(shù)據(jù)溢出}else if (g1 < 0) {g1 = 0;//控制數(shù)據(jù)溢出}if (pg > 255){pg = 255;//控制數(shù)據(jù)溢出}else if (pg < 0) {pg = 0;//控制數(shù)據(jù)溢出}if (G > g1 || G < pg){return 0;}}else if (pg == 0) { if (G != g1) { return 0; } }}}{if (pb >= 1){b = b1;b1 += pb;//最大偏移pb = b - pb;//最小偏移if (b1 > 255) {b1 = 255;//控制數(shù)據(jù)溢出}else if (b1 < 0) {b1 = 0;//控制數(shù)據(jù)溢出}if (pb > 255){pb = 255;//控制數(shù)據(jù)溢出}else if (pb < 0) {pb = 0;//控制數(shù)據(jù)溢出}if (B > b1 || B < pb){return 0;}}else if (pb == 0) { if (B != b1) { return 0; } }}return 1;} //原文鏈接:https ://blog.csdn.net/qq_43345204/article/details/83476693 void Getcol_a(CString str, int& a, int& b) {CString utoa, utoa1;int inlock = 0;CString str1;int strl = str.GetLength();for (size_t i = 0; i < strl; i++){str1 = str.Mid(i, 1);if (str1 == "-"){inlock = 1;}if (inlock == 0){utoa += str1;str1 = "";}if (inlock == 1 && str1 != "-"){utoa1 += str1;str1 = "";}}a = StrToInt(utoa);b = StrToInt(utoa1); } int TKdmsoft::FindStr(int x1, int y1, int x2, int y2, const char* str, const char* color_format, int& X, int& Y) {//CBitmap, HBitmap, BITMAP.if (g_hwnd==0){return -1;}HDC hDC = GetWindowDC(g_hwnd);// ::GetWindowDC(hwnd);//獲取DC HDC hDCMem = ::CreateCompatibleDC(hDC);//創(chuàng)建兼容DC RECT rect;rect.right = y2 - y1;//獲取屏幕高度rect.bottom = x2 - x1;//獲取屏幕寬度HBITMAP hBitMap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);//創(chuàng)建兼容位圖 HBITMAP hOldMap = (HBITMAP)::SelectObject(hDCMem, hBitMap);//將位圖選入DC。并保存返回值 ::BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 8+x1,31+y1, SRCCOPY);//將屏幕DC的圖象拷貝到內存DC中 CImage bm;bm.Attach(hBitMap);//bm.Save("d:\\2345.bmp");//假設文件后綴為.bmp,則保存為為bmp格式 CDC* pDC = CDC::FromHandle(hDCMem);int width, high;width = x2 - x1;//bm.GetWidth();//獲取圖像的寬度high = y2 - y1; //bm.GetHeight();//獲取圖像的高度if (width <= 0 || high <= 0){return -1;}int c1, c2;char** FindStrpm = (char**) new char*[width+100]; //分配一個數(shù)組來裝圖片像數(shù)for (size_t i = 0; i < width+100; i++){FindStrpm[i] = new char[high+100];}if (QSC(color_format, c1, c2) == -1)//取回顏色和偏色的數(shù)值{return -1;}COLORREF cor;int a = 0;int R = 0, G = 0, B = 0;for (size_t y = 0; y < width; y++){for (size_t x = 0; x < high; x++){if (x==12 && y==25){x = x;}cor = pDC->GetPixel(x, y);//CString str1; int tpe;//memcpy(&tpe,&cor,3);tpe = redToGreen(cor, c1, c2);//轉換主屏幕;if (tpe == -1){return -1;}if (tpe==1){tpe = tpe;}FindStrpm[x][y] = tpe;}}bm.Detach();//釋放 ::DeleteObject(hBitMap);::DeleteDC(hDCMem);::DeleteDC(hDC);//for (size_t i = 0; i < width+100; i++)//{// delete[] FindStrpm[i] ;//}delete[] FindStrpm;int uot_x = -1, uot_y = -1;int w, h;//GetDict("C0180300600$方$0.0.8$2");int b = 0, uto=0;char* chh= NULL;chh=GetDictWh(str, w, h, uto);if (w <= 0 || h <= 0){return -1;}a = 0;int** FindS = (int**) new int* [w];for (int i = 0; i < w; i++){FindS[i] = new int[h];}int zthmax = dictwh[0].w;int ztdex = 0;for (size_t x = 0; x < w; x++){if (zthmax==0){ztdex++;zthmax = dictwh[ztdex].w;}zthmax--;for (size_t y = 0; y < h; y++){char ch[2] = { 0 };if (y<=dictwh[ztdex].h){memcpy(ch, chh + a, 1);int temp = StrToInt(ch);FindS[x][y] = temp;a++;}else{FindS[x][y] = 0;}}}delete[] dictwh;int uto1=0;// = Dict.yxxs, uto1 = 0;//記錄找到的有效像數(shù)bool ret = false;a = 0, b = 0;for (size_t x = 0; x < width; x++){if (width - x >= w)//寬度大于等于字體寬度才開始尋找不然從下一行開始{for (size_t y = 0; y < high; y++){if (high - y >= h)//高度度大于等于字體寬度才開始尋找不然從下一行開始{for (size_t yy = 0; yy < w; yy++){for (size_t hh = 0; hh < h; hh++){ int xxx = x + yy, yyy = y + hh;int b1 = FindStrpm[xxx][yyy], b2 = FindS[yy][hh];if (b2 == 1){if (b1 != b2){uto1 = 0;a = 0;ret = false;uot_x = -1;uot_y = -1;break;;}else{ret = true;}if (a == 0 && ret == true){uot_x = x;uot_y = y;}uto1++;a++;if (uto1 >= uto){break;}}}if (uto1 >= uto){break;}}}if (uto1 >= uto){break;}}}if (uto1 >= uto){break;}}for (int i = 0; i < w; i++){delete[] FindS[i];}delete[] FindS;if (uot_x >= 0){X = uot_x+x1;Y = uot_y+y1;}else{X = -1;Y = -1;return 1;}return 1; }long TKdmsoft::SetDict(char* file) {if (file == NULL|| strpath == NULL){return -1;}char path[256] = {0};memcpy(path, strpath,strlen(strpath));memcpy(path+ strlen(strpath), file, strlen(file));HANDLE hand =CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD Len = 0;ULONGLONG size;CFileStatus fileStatus;if (CFile::GetStatus(path,fileStatus)){size = fileStatus.m_size;}char* str=new char[size];memset(str, 0, sizeof(str));ReadFile(hand, str, size, &Len, NULL);int a = 0;char bj[3] = {0};for (UINT64 i = 0; i < Len; i++){memcpy(bj, str + i, 2);if (strcmp(bj,"\r\n") == 0){a++;}}Dict = new MyDict[a];DictSize = a;memset(Dict, 0, sizeof(Dict));int b = 0,c=0;char srz[4096] = {0};for (QWORD i = 0; i < Len; i++){memcpy(bj, str + i, 2);if (strcmp(bj,"\r\n")!=0&&bj[0]!='\n'){srz[b] = str[i];b++;}if (strcmp(bj, "\r\n") == 0){GetDict(c,srz);c++;b = 0;memset(srz,0,sizeof(srz)*sizeof(char));}//memset}SetDlgItemText(g_hwnd,EDIT_ZT, str);CloseHandle(hand);delete[] str;return 0; }long TKdmsoft::SetPath(char* path) {if (path==NULL){return -1;}if (strlen(path)<=2){return -1;}strpath = path;return 1; }int TKdmsoft::GetDict(int dex, const char* str_a) {char str[256] = { 0 }, str1[2] = { 0 };int strl = strlen(str_a);char Dict1[256] = { 0 }; //要操作字體的點陣int dit = 0, Nett = 0, czt = 0, cht = 0;char Neam[256] = { 0 }; //要操作的字符名稱char czs[256] = { 0 };//有效像數(shù)char chs[256] = { 0 };//豎排行數(shù)int strlock = 0;for (UINT64 i = 0; i < strl; i++){str1[0] = str_a[i];if (strcmp(str1, "$") == 0){strlock++;}if (strlock == 0 && strcmp(str1, "$") != 0){Dict1[dit] = str1[0];dit++;str1[0] = 0;}if (strlock == 1 && strcmp(str1, "$") != 0){Neam[Nett] = str1[0];Nett++;str1[0] = 0;}if (strlock == 2 && strcmp(str1, "$") != 0){czs[czt] = str1[0];czt++;str1[0] = 0;}if (strlock == 3 && strcmp(str1, "$") != 0){chs[cht] += str1[0];cht++;str1[0] = 0;}}if (strlen(Dict1) <= 0 || strlen(Neam) <= 0 || strlen(czs) <= 0 || strlen(chs) <= 0){return 0;//讀取錯誤返回0}char ch[3] = { 0 };CString SST=HexToBin(Dict1);//轉換到二進制Dict[dex].Dict = new char[SST.GetLength()];memset(Dict[dex].Dict, 0, SST.GetLength());memcpy(Dict[dex].Dict, SST.GetBuffer(), SST.GetLength());memcpy(ch,Neam,2);if (!IsChinese(ch)){memcpy(Dict[dex].Neam, Neam, 1);}else{memcpy(&Dict[dex].Neam, Neam, 2);} memcpy(ch, czs+4, 4);Dict[dex].yxxs = StrToInt(ch);//字符轉換到整數(shù)Dict[dex].spxs = StrToInt(chs);//這是豎排行數(shù)return 1; }int GetDictSize(const char* str) {int strl = strlen(str);int strlock = 0;int ret = 0;int b = 0;for (size_t i = 0; i < strl; i++){char bj[3] = { 0 };if (strlock==0){if (strl - i >= 1){memcpy(bj, str + i, 2);}else{memset(bj, 0, sizeof(bj));memcpy(bj, str + i, 1);}if (IsChinese(bj)){b++;ret = i;strlock = 1;}}if (strlock == 1&&i-ret==1){strlock = 0;ret = 0;}}strl = strl - b * 2;b = b + strl;return b; } char* TKdmsoft::GetDictWh(const char* str, int& w, int& h,int& uto) {char retstr[4096] = {0};if (str==NULL){return "";}int strl = GetDictSize(str);ZTsize = strl;dictwh = new MyDictwh[strl];int a = 0,hh=0,sst=0,dex=0,b=0;for (size_t i = 0; i < strl; i++){a = 0;for (size_t j = 0; j < DictSize; j++){char bj[3] = {0};memcpy(bj, str , 2);if (!IsChinese(bj)){memcpy(bj, str + j, 1);}if (strcmp(Dict[j].Neam, bj) == 0){a = j + 1;break;}}if (a>0){ h = Dict[a-1].spxs;//字體高度if (h < 11){h = 11;}if (hh==0){hh = h;} else{if (h>hh){hh = h;}}if (sst==0){sst = strlen(Dict[a - 1].Dict);memcpy(retstr, Dict[a - 1].Dict, sst);}else{memcpy(retstr+ sst, Dict[a - 1].Dict, strlen(Dict[a - 1].Dict));sst+= strlen(Dict[a - 1].Dict);}b= strlen(Dict[a - 1].Dict) / h;//字體寬度w += b;dictwh[dex].w = b;dictwh[dex].h = h;uto += Dict[a - 1].yxxs;a = 0;}}if (hh==0){w = 0;h = 0;uto = 0;dictwh = NULL;return "";} h = hh;str = retstr;return retstr; }

下面是調用的CPP

// FinndstrExDlg.cpp: 實現(xiàn)文件 //#include "pch.h" #include "framework.h" #include "FinndstrEx.h" #include "FinndstrExDlg.h" #include "afxdialogex.h" #include<iostream> #include <fstream> #include "dlgs.h" #include "math.h" #include "stdlib.h" #include "MFC進制轉換.h" #include "FindstrEx.h" //#include <opencv2\opencv.hpp>TKdmsoft dm; using namespace std;#ifdef _DEBUG #define new DEBUG_NEW #endif// CFinndstrExDlg 對話框CFinndstrExDlg::CFinndstrExDlg(CWnd* pParent /*=nullptr*/): CDialogEx(IDD_FINNDSTREX_DIALOG, pParent) {m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }void CFinndstrExDlg::DoDataExchange(CDataExchange* pDX) {CDialogEx::DoDataExchange(pDX); }BEGIN_MESSAGE_MAP(CFinndstrExDlg, CDialogEx)ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1, &CFinndstrExDlg::OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON2, &CFinndstrExDlg::OnBnClickedButton2)ON_BN_CLICKED(IDC_BUTTON3, &CFinndstrExDlg::OnBnClickedButton3) END_MESSAGE_MAP()// CFinndstrExDlg 消息處理程序BOOL CFinndstrExDlg::OnInitDialog() {CDialogEx::OnInitDialog();// 設置此對話框的圖標。 當應用程序主窗口不是對話框時,框架將自動// 執(zhí)行此操作SetIcon(m_hIcon, TRUE); // 設置大圖標SetIcon(m_hIcon, FALSE); // 設置小圖標// TODO: 在此添加額外的初始化代碼dm.Sethwnd(m_hWnd);//設置需要找字的窗口CStatic* pwnd = (CStatic*)GetDlgItem(IDC_PIC1); //IDC_STATIC //pwnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);pwnd->ModifyStyle(0xf, SS_BITMAP);HBITMAP bmp = (HBITMAP)::LoadImage(GetModuleHandle(NULL), "d:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);pwnd->SetBitmap(bmp);//打開圖片return TRUE; // 除非將焦點設置到控件,否則返回 TRUE }// 如果向對話框添加最小化按鈕,則需要下面的代碼 // 來繪制該圖標。 對于使用文檔/視圖模型的 MFC 應用程序, // 這將由框架自動完成。void CFinndstrExDlg::OnPaint() {if (IsIconic()){CPaintDC dc(this); // 用于繪制的設備上下文SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);// 使圖標在工作區(qū)矩形中居中int cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// 繪制圖標dc.DrawIcon(x, y, m_hIcon);}else{CDialogEx::OnPaint();} }//當用戶拖動最小化窗口時系統(tǒng)調用此函數(shù)取得光標 //顯示。 HCURSOR CFinndstrExDlg::OnQueryDragIcon() {return static_cast<HCURSOR>(m_hIcon); }void CFinndstrExDlg::OnBnClickedButton1() { TODO: 在此添加控件通知處理程序代碼dm.SetPath("d:\\");dm.SetDict("找字.txt");CString cstr,str;//GetDlgItemText(EDIT_x, cstr);//cstr.Format("點陣信息:%s\r\n字符名稱:%s\r\n有效像數(shù):%d\r\n豎排行數(shù):%d", Dict.Dict, Dict.Neam, Dict.yxxs, Dict.spxs);//GetDlgItemText(EDIT_y, str);int x=-1, y=-1;//time_t t; time(&t);//tm* m=localtime(&t);////int sbb= m->tm_sec;dm.FindStr(0, 1, 215, 113, "方方", "ff0000-050505", x, y);if (x>=0){str.Format("%d", x);SetDlgItemText(EDIT_x, str);str.Format("%d", y);SetDlgItemText(EDIT_y, str);}//intTo101(0xC0180300600);// time(&t);//m = localtime(&t);//int sbb1 = m->tm_sec;//str.Format("%d", sbb1- sbb);//AfxMessageBox(str);//CString str= HexToBin("C0180300600");//SetDlgItemText(EDIT_ZT, g_str1);//SetDlgItemText(EDIT1_ARRAY, g_str); //原文鏈接:https ://blog.csdn.net/mengsuifengc/article/details/109228725 }void CFinndstrExDlg::OnBnClickedButton2() {// TODO: 在此添加控件通知處理程序代碼CString str;GetDlgItemText(EDIT_ZT, str);str=BinToHex(str);SetDlgItemText(EDIT_ZT, str); }void CFinndstrExDlg::OnBnClickedButton3() {// TODO: 在此添加控件通知處理程序代碼dm.CloseTk(); }

還不是很完善大家自己完善了!

總結

以上是生活随笔為你收集整理的高仿大漠找字FindStr的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。