(ADO)数据库中存取BMP图像,急!!!!!!!!!

哟西哟西地 2004-02-03 12:45:50
谁有将图像写入数据库(ADO)的相关代码,我刚学可总不能实现!!!!!!!!!

哪位兄弟帮忙?

有代码最好,
...全文
8 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
AkiraChing 2004-02-03
储存图片

rs.CreateInstance(__uuidof(Recordset));

rs->Open("相片",_variant_t((IDispatch *)m_pConn,true), adOpenKeyset,
adLockOptimistic, adCmdTable);
rs->AddNew();
_variant_t var;
COleDateTime tDate;
m_datePic.GetTime(tDate);
var.vt=VT_DATE;
var.date=tDate;
rs->GetFields()->GetItem("拍摄日期")->Value=var;
var.Clear();
var.vt=VT_BSTR;
var.bstrVal=strTheme.AllocSysString();
rs->GetFields()->GetItem("主题名称")->Value=var;
var.bstrVal=strId.AllocSysString();
rs->GetFields()->GetItem("照片 ID")->Value=var;
CFile file;
if( !file.Open( m_strPicfile, CFile::modeRead) )
return ;
DWORD uFilesize =(DWORD) file.GetLength();
char* pBuffer = new char[uFilesize + 1];
if(pBuffer!=NULL)
{
ZeroMemory(pBuffer,uFilesize + 1);
VERIFY(file.Read(pBuffer,uFilesize)==uFilesize);

VARIANT varImage;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];

rgsabound[0].lLbound = 0;
rgsabound[0].cElements = uFilesize;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
for (long i = 0; i < (long)uFilesize; i++)
SafeArrayPutElement (psa, &i, pBuffer++);
varImage.vt = VT_ARRAY | VT_UI1;
varImage.parray = psa;
rs->GetFields()->GetItem("图片")->AppendChunk(varImage);

}

rs->Update();
pBuffer=pBuffer-uFilesize;
if(pBuffer)
{
delete [] pBuffer;
pBuffer=NULL;
}
MessageBox("添加数据成功!","提示",MB_OK|MB_ICONINFORMATION);
}
catch (_com_error e)
{
PrintComError(e);
}

if(rs->State)
rs->Close();
回复
AkiraChing 2004-02-03
读取图片
HGLOBAL hgImageMem = NULL;
LPVOID lpvImageMem = NULL;

long lImageSize = rs->GetFields()->GetItem("图片")->ActualSize;

if(lImageSize > 0)
{
_variant_t varImage;
varImage = rs->GetFields()->GetItem("图片")->GetChunk(lImageSize);
if(varImage.vt == (VT_ARRAY | VT_UI1))
{

hgImageMem = GlobalAlloc(GHND, lImageSize);
if(hgImageMem!=NULL)
{
lpvImageMem = GlobalLock( hgImageMem);
char *pBuffer= NULL;
SafeArrayAccessData(varImage.parray,(void **)&pBuffer);
CopyMemory(lpvImageMem,pBuffer,lImageSize);
SafeArrayUnaccessData (varImage.parray);
CFile file("a.jpg",CFile::modeWrite|CFile::modeCreate);
file.Write(lpvImageMem,lImageSize);
file.Close();
}
}
}

GlobalUnlock(hgImageMem);
lpvImageMem=NULL;
GlobalFree(hgImageMem);
回复
bluebohe 2004-02-03
http://www.csdn.net/develop/Read_Article.asp?Id=15019
回复
发动态
发帖子
数据库
创建于2007-09-28

3942

社区成员

VC/MFC 数据库
申请成为版主
社区公告
暂无公告