我在做一个基于内容的图片检索系统,现在提取了一个颜色特征一维数组h[k] 0<=k<=255
每幅图片都有一个特征需要存入。
而同时还要另外建一个表将图片的文件头信息和像素数据分开存入
将指针定位到像素起始位置后怎么将整个像素数据格式为二进制流然后存入?
而特征数组怎么存入,也是格式为二进制存入吗?怎么格式化?
请大家不吝赐教
每幅图片都有一个特征需要存入。
而同时还要另外建一个表将图片的文件头信息和像素数据分开存入
将指针定位到像素起始位置后怎么将整个像素数据格式为二进制流然后存入?
而特征数组怎么存入,也是格式为二进制存入吗?怎么格式化?
请大家不吝赐教
先谢谢了。
void CInfoFormView::SaveInfo(LPCSTR strPathName)
{
CFile imagefile; VARIANT varBLOB;
BYTE* pbuf; long nLength;
long nMaxID; char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT]; _splitpath(strPathName, drive, dir, fname, ext); if (!stricmp(ext, ".bmp"))
{
strcpy(ext, ".bmp");
pImage = new CImageBmp;
pImage->ReadFile(strPathName, &nLength);
}
if (!stricmp(ext, ".gif"))
{
strcpy(ext, ".gif");
pImage = new CImageGif;
pImage->ReadFile(strPathName, &nLength);
}
if (!stricmp(ext, ".jpg") || !stricmp(ext,".jpeg"))
{
strcpy(ext, ".jpg");
pImage = new CImageJpg;
pImage->ReadFile(strPathName, &nLength);
} try
{
theApp.m_pRecordset->Close();
CString str = "select * from tbl_image";
_bstr_t bstrQuery = str;
theApp.m_pRecordset->Open(bstrQuery, _variant_t((IDispatch *)theApp.m_pConnection, true), adOpenDynamic, adLockOptimistic, adCmdText); theApp.m_pRecordset->MoveLast();
nMaxID = (long)theApp.m_pRecordset->Fields->GetItem("ID")->Value;
theApp.m_pRecordset->AddNew(); theApp.m_pRecordset->Fields->GetItem("ID")->Value = (_variant_t)(long)(nMaxID+1);
theApp.m_pRecordset->Fields->GetItem("NAME")->Value = (_bstr_t)fname;
theApp.m_pRecordset->Fields->GetItem("WIDTH")->Value = (_variant_t)(long)(pImage->DIBWidth());
theApp.m_pRecordset->Fields->GetItem("HEIGHT")->Value = (_variant_t)(long)(pImage->DIBHeight());
theApp.m_pRecordset->Fields->GetItem("CONTENTLENGTH")->Value = (_variant_t)nLength;
theApp.m_pRecordset->Fields->GetItem("MIMETYPE")->Value = (_bstr_t)ext; delete pImage; if(0 == imagefile.Open(strPathName, CFile::modeRead))
return; pbuf = new BYTE[nLength + 2];
if(pbuf == NULL)
return; imagefile.Read(pbuf, nLength); BYTE *pBufEx;
pBufEx = pbuf; SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nLength; psa = SafeArrayCreate(VT_UI1, 1, rgsabound); for (long i = 0; i < nLength; i++)
SafeArrayPutElement(psa, &i, pBufEx++); varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa; theApp.m_pRecordset->Fields->GetItem("IMAGE_BLOB")->AppendChunk(varBLOB);
theApp.m_pRecordset->Update(); theApp.m_pRecordset->Requery(adCmdText); ContentBuild();
}
catch(_com_error e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
CString sError;
sError.Format("Source : %s \n Description : %s\n", (LPCSTR)bstrSource, (LPCSTR)bstrDescription);
AfxMessageBox(sError);
}
}Try it!