怎樣可以提取出一個漢字每個筆畫起點的相對坐標位置?跪求 急求
uj5u.com熱心網友回復:
說說我的經驗:
如果是作業需求,樓主可以查詢相關 專利和 論文,再順藤摸瓜,做進一步的作業。
如果是學習,也可以從中得到一些啟發。
uj5u.com熱心網友回復:
僅供參考:#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
#include <string.h>
#include <stdio.h>
char ch[3];
wchar_t uc[2];
int i,un=0,n;
HFONT hfont,ohfont;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
RECT r;
COLORREF oc;
int iNumPts;
LPPOINT lpPoints; // Path data points
LPBYTE lpTypes; // Path data types
HPEN hOldPen;
switch(message) {
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_KEYUP:
if (wParam==VK_ESCAPE||wParam==VK_SPACE) PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
hdc = ps.hdc; // the device context to draw in
GetClientRect(hWnd, &r); // Obtain the window's client rectangle
ohfont=(HFONT)SelectObject(hdc,hfont);
oc=SetTextColor(hdc,0x00FFFFFF);
SetBkMode(hdc, TRANSPARENT);
BeginPath(hdc);
if (un>0) TextOutW(hdc,r.left+100,r.top+100,uc,un);
else TextOut(hdc,r.left+100,r.top+100,ch,strlen(ch));
EndPath(hdc);
// FlattenPath(hdc);//將所有Bezier曲線段轉換為直線段
iNumPts = GetPath(hdc, NULL, NULL, 0);
lpPoints = (LPPOINT)GlobalAlloc(GPTR, sizeof(POINT) * iNumPts);
lpTypes = (LPBYTE)GlobalAlloc(GPTR, iNumPts);
iNumPts = GetPath(hdc, lpPoints, lpTypes, iNumPts);
hOldPen = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID,0,RGB(0,0,255)));
StrokePath(hdc);
// for (i=0; i<iNumPts; i++) {
// switch (lpTypes[i]) {
// case PT_MOVETO :
// MoveToEx(hdc, lpPoints[i].x, lpPoints[i].y, NULL);
// break;
//
// case PT_LINETO | PT_CLOSEFIGURE:
// case PT_LINETO :
// LineTo(hdc, lpPoints[i].x, lpPoints[i].y);
// break;
//
// case PT_BEZIERTO | PT_CLOSEFIGURE:
// case PT_BEZIERTO :
// PolyBezierTo(hdc, &lpPoints[i], 3);
// i+=2;
// break;
// }
// }
for (i=0; i<iNumPts; i++) {
switch (lpTypes[i]) {
case PT_MOVETO :
SetPixel(hdc, lpPoints[i].x, lpPoints[i].y, RGB(255,0,255));
break;
case PT_LINETO | PT_CLOSEFIGURE:
case PT_LINETO :
SetPixel(hdc, lpPoints[i].x, lpPoints[i].y, RGB(255,255,255));
break;
case PT_BEZIERTO | PT_CLOSEFIGURE:
case PT_BEZIERTO :
SetPixel(hdc, lpPoints[i ].x, lpPoints[i ].y, RGB(255, 0,0));
SetPixel(hdc, lpPoints[i+1].x, lpPoints[i+1].y, RGB( 0,255,0));
SetPixel(hdc, lpPoints[i+2].x, lpPoints[i+2].y, RGB(255,255,0));
i+=2;
break;
}
}
DeleteObject(SelectObject(hdc, hOldPen));
GlobalFree(lpPoints);
GlobalFree(lpTypes);
SelectObject(hdc,ohfont);
SetTextColor(hdc,oc);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASS wc = {0};
HBRUSH hbrh;
DWORD charset=1;
hbrh=CreateSolidBrush(0x00000000);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = hbrh;
wc.lpszClassName = "minwindowsapp";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if (lpCmdLine[0]==0) {
HELP:
DeleteObject(hbrh);
MessageBox(NULL,"FontPath 字|0xXX|0xXXXX|\\uXXXX|\\uXXXX\\uXXXX [charset] 字體名稱\n\n"
" ANSI_CHARSET 0\n"
" DEFAULT_CHARSET 1\n"
" SYMBOL_CHARSET 2\n"
" SHIFTJIS_CHARSET 128\n"
" HANGEUL_CHARSET 129\n"
" GB2312_CHARSET 134\n"
"CHINESEBIG5_CHARSET 136\n"
" OEM_CHARSET 255\n"
" JOHAB_CHARSET 130\n"
" HEBREW_CHARSET 177\n"
" ARABIC_CHARSET 178\n"
" GREEK_CHARSET 161\n"
" TURKISH_CHARSET 162\n"
" VIETNAMESE_CHARSET 163\n"
" THAI_CHARSET 222\n"
" EASTEUROPE_CHARSET 238\n"
" RUSSIAN_CHARSET 204\n"
" MAC_CHARSET 77\n"
" BALTIC_CHARSET 186"
,"FontPath",MB_OK);
return 4;
}
uc[0]=0;uc[1]=0;
if (2==sscanf(lpCmdLine,"\\u%hx\\u%hx%n",&uc[0],&uc[1],&i)) {
un=2;
} else if (1==sscanf(lpCmdLine,"\\u%hx%n",&uc[0],&i)) {
un=1;ch[0]=' ';ch[1]=0;
} else if (1==sscanf(lpCmdLine,"0x%hx%n",ch,&i)) {
if (ch[1]) {ch[2]=ch[0];ch[0]=ch[1];ch[1]=ch[2];}
ch[2]=0;
} else if (1==sscanf(lpCmdLine,"%2s%n",ch,&i)) {
ch[2]=0;
}
while (1) {
if (' '==lpCmdLine[i]) i++; else break;
}
if (0==lpCmdLine[i]) goto HELP;
if (1==sscanf(lpCmdLine+i,"%d%n",&charset,&n)) i+=n;
while (1) {
if (' '==lpCmdLine[i]) i++; else break;
}
if (0==lpCmdLine[i]) goto HELP;
hfont = CreateFont(GetSystemMetrics(SM_CYSCREEN)-200, 0, 0, 0, 0, 0, 0, 0, charset, 0, 0, 0, 0, lpCmdLine+i);
if (NULL==hfont) {
DeleteObject(hbrh);
MessageBox(NULL,"不支持該字體!","FontPath",MB_OK);
return 3;
}
if(FAILED(RegisterClass(&wc)) ) {DeleteObject(hbrh);return 1;}
if(FAILED(CreateWindow(wc.lpszClassName,
"Minimal Windows Application",
WS_POPUP|WS_VISIBLE,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInstance,
NULL))) {
DeleteObject(hbrh);
return 2;
}
while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
DispatchMessage( &msg );
}
DeleteObject(hfont);
DeleteObject(hbrh);
return 0;
}
//FontPath \ud854\udc00 宋體-方正超大字符集
//顯示‘左邊上土下羊,右邊皮’這個字。
#if 0
代理項或代理項對是一對共同表示單個字符的 16 位 Unicode 編碼值。需要記住的關鍵一點是:
代理項對實際上是 32 位單個字符,不能再假定一個 16 位 Unicode 編碼值正好映射到一個字符。
使用代理項對
代理項對的第一個值是高代理項,包含介于 U+D800 到 U+DBFF 范圍內的 16 位代碼值。
該對的第二個值是低代理項,包含介于 U+DC00 到 U+DFFF 范圍內的值。通過使用代理項對,
16 位 Unicode 編碼系統可以對已由 Unicode 標準定義的一百多萬個其他字符 (220) 進行尋址。
在傳遞給 XmlTextWriter 方法的任何字串中都可以使用代理項字符。不過,代理項字符在撰寫的
XML 中應該有效。例如,萬維網聯合會 (W3C) 建議不允許在元素或屬性的名稱中使用代理項字符。
如果字串包含無效的代理項對,則引發例外。
另外,可以使用 WriteSurrogateCharEntity 寫出與代理項對相對應的字符物體。字符物體以十六
進制格式寫出,并用以下公式生成:
(highChar -0xD800) * 0x400 + (lowChar -0xDC00) + 0x10000
如果字串包含無效的代理項對,則引發例外。下面的示例顯示將代理項對作為輸入的 WriteSurrogateCharEntity 方法。
C#復制
// The following line writes 𐀀.
WriteSurrogateCharEntity ('\uDC00', '\uD800');
下面的示例生成一個代理項對檔案,將其加載到 XmlReader 中,并用新的檔案名保存檔案。
然后,原始檔案和新檔案被加載回應用程式的 XML 檔案物件模型 (DOM) 結構中以進行比較。
C#復制
char lowChar, highChar;
char [] charArray = new char[10];
FileStream targetFile = new FileStream("SurrogatePair.xml",
FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
lowChar = Convert.ToChar(0xDC00);
highChar = Convert.ToChar(0xD800);
XmlTextWriter tw = new XmlTextWriter(targetFile, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartElement("root");
tw.WriteStartAttribute("test", null);
tw.WriteSurrogateCharEntity(lowChar, highChar);
lowChar = Convert.ToChar(0xDC01);
highChar = Convert.ToChar(0xD801);
tw.WriteSurrogateCharEntity(lowChar, highChar);
lowChar = Convert.ToChar(0xDFFF);
highChar = Convert.ToChar(0xDBFF);
tw.WriteSurrogateCharEntity(lowChar, highChar);
// Add 10 random surrogate pairs.
// As Unicode, the high bytes are in lower
// memory; for example, word 6A21 as 21 6A.
// The high or low is in the logical sense.
Random random = new Random();
for (int i = 0; i < 10; ++i) {
lowChar = Convert.ToChar(random.Next(0xDC00, 0xE000));
highChar = Convert.ToChar(random.Next(0xD800, 0xDC00));
charArray[i] = highChar;
charArray[++i] = lowChar;
}
tw.WriteChars(charArray, 0, charArray.Length);
for (int i = 0; i < 10; ++i) {
lowChar = Convert.ToChar(random.Next(0xDC00, 0xE000));
highChar = Convert.ToChar(random.Next(0xD800, 0xDC00));
tw.WriteSurrogateCharEntity(lowChar, highChar);
}
tw.WriteEndAttribute();
tw.WriteEndElement();
tw.Flush();
tw.Close();
XmlTextReader r = new XmlTextReader("SurrogatePair.xml");
r.Read();
r.MoveToFirstAttribute();
targetFile = new FileStream("SurrogatePairFromReader.xml",
FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
tw = new XmlTextWriter(targetFile, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartElement("root");
tw.WriteStartAttribute("test", null);
tw.WriteString(r.Value);
tw.WriteEndAttribute();
tw.WriteEndElement();
tw.Flush();
tw.Close();
// Load both result files into the DOM and compare.
XmlDocument doc1 = new XmlDocument();
XmlDocument doc2 = new XmlDocument();
doc1.Load("SurrogatePair.xml");
doc2.Load("SurrogatePairFromReader.xml");
if (doc1.InnerXml != doc2.InnerXml) {
Console.WriteLine("Surrogate Pair test case failed");
}
在使用 WriteChars 方法(一次寫出一個緩沖區的資料)寫出時,輸入中的代理項對可能
會在一個緩沖區內被意外拆分。由于代理項值是定義完善的,如果 WriteChars 遇到來自
較低范圍或者較高范圍的 Unicode 值,它將該值標識為代理項對的一半。當遇到
WriteChars 將導致從拆分代理項對的緩沖區寫入的情況時,將引發例外。使用
IsHighSurrogate 方法檢查緩沖區是否以高代理項字符結束。如果緩沖區中的最后一個
字符不是高代理項,可以將該緩沖區傳遞給 WriteChars 方法。
請參見
概念
使用 XmlTextWriter 創建格式正確的 XML
XmlTextWriter 的 XML 輸出格式設定
XmlTextWriter 的命名空間功能
#endif
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
#pragma warning(disable:4996)
//...
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/81930.html
標籤:圖形處理/算法
上一篇:靜止目標檢測
