//设置手写识别语言
CComPtr<IInkRecognizers> spIInkRecognizers;
if(SUCCEEDED(spIInkRecognizers.CoCreateInstance(CLSID_InkRecognizers)))
{
// 获取识别器数目
LONG count = 0;
hr = spIInkRecognizers->get_Count(&count);
if(count > 0)
{
CComPtr<IInkRecognizer> spIInkRecognizer;
for (LONG i = 0; i < count; i++)
{
if (FAILED(spIInkRecognizers->Item(i, &spIInkRecognizer)))
continue;
CComVariant vLanguages;
if (SUCCEEDED(spIInkRecognizer->get_Languages(&vLanguages)))
{
if ((VT_ARRAY == (VT_ARRAY & vLanguages.vt))
&& (NULL != vLanguages.parray)
&& (0 < vLanguages.parray->rgsabound[0].cElements))
{
CComBSTR bstrName;
if (SUCCEEDED(spIInkRecognizer->get_Name(&bstrName)))
{
//LOG_D("lan = %s", CString(bstrName));
if(wcscmp(bstrName, L"Microsoft 中文(简体)手写识别器") == 0)
{
m_InkRecoContext->Release();
spIInkRecognizer->CreateRecognizerContext(&m_InkRecoContext);
break;
}
}
}
spIInkRecognizer.Release();
}
}
}
}
//手写识别结果
vector<CString> Recognise()
{
vector<CString> vecRet;
IInkStrokes* pInkStrokes = NULL;
HRESULT hr = S_FALSE;
if(m_InkDisp && (hr = m_InkDisp->get_Strokes(&pInkStrokes)) == S_OK)
{
hr = m_InkRecoContext->putref_Strokes(pInkStrokes);
if (SUCCEEDED(hr))
{
//利用识别指针获取识别结果
IInkRecognitionResult* pIInkRecoResult = NULL;
InkRecognitionStatus RecognitionStatus;
hr = m_InkRecoContext->Recognize(&RecognitionStatus, &pIInkRecoResult);
if (SUCCEEDED(hr) && RecognitionStatus == IRS_NoError)
{
CComPtr<IInkRecognitionAlternates> spIInkRecoAlternates;
hr = pIInkRecoResult->AlternatesFromSelection(
0, // in: selection start
-1, // in: selection length; -1 means "up to the last one"
10, // in: the number of alternates we're interested in
&spIInkRecoAlternates // out: the receiving pointer
);
// Count the returned alternates, it may be less then we asked for
long lCount = 0;
if (SUCCEEDED(hr) && SUCCEEDED(spIInkRecoAlternates->get_Count(&lCount)))
{
// Get the alternate strings
IInkRecognitionAlternate* pIInkRecoAlternate = NULL;
for (LONG iItem = 0; (iItem < lCount) && (iItem < 10); iItem++)
{
// Get the alternate string if there is one
if (SUCCEEDED(spIInkRecoAlternates->Item(iItem, &pIInkRecoAlternate)))
{
CComBSTR bstr;
if (SUCCEEDED(pIInkRecoAlternate->get_String(&bstr)))
{
vecRet.push_back(bstr.Copy());
}
pIInkRecoAlternate->Release();
}
}
}
pIInkRecoResult->Release();
}
m_InkRecoContext->putref_Strokes(NULL);
}
pInkStrokes->Release();
}
return vecRet;
}
//撤销
void Undo()
{
IInkStrokes* pInkStrokes = NULL;
HRESULT hr = S_FALSE;
if (m_InkDisp && (hr = m_InkDisp->get_Strokes(&pInkStrokes)) == S_OK)
{
long nCount = 0;
pInkStrokes->get_Count(&nCount);
if (nCount > 0)
{
IInkStrokeDisp* pInkStrokeDisp = NULL;
if (pInkStrokes->Item(nCount - 1, &pInkStrokeDisp) == S_OK)
{
pInkStrokes->Remove(pInkStrokeDisp);
m_InkDisp->DeleteStroke(pInkStrokeDisp);
pInkStrokeDisp->Release();
InvalidateRect(m_hWnd, NULL, TRUE);
}
}
pInkStrokes->Release();
}
}
cpp手写识别
最新推荐文章于 2024-08-10 22:58:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)