FILE *fp =fopen(strFile,"rb");
if(fp)
{
fseek(fp,0,SEEK_END);
long len=ftell(fp);
fseek(fp,0,SEEK_SET);
char *pBuf=(char *)malloc(sizeof(char)*(len+1));
if(pBuf)
{
fread(pBuf,1,len,fp);
pPDFView->OpenMem( (short* )pBuf,len,NULL)
}
fclose(fp);
}
________________________________________________________________
文件写入数据库字段代码:
ADOQuery1->Append() ;
ADOQuery1->Fields->Fields[0]->AsInteger =111;
TBlobField *wj =(TBlobField*)ADOQuery3->Fields->Fields[3];
wj->LoadFromFile("D:\\外形图.pdf" ) ;
ADOQuery3->Post() ;
________________________________________________________________
从数据库字段读到流中,再打开,就会报错。
TStream *stream = ADOQuery1-> CreateBlobStream( ADOQuery1->Fields->Fields[3] ,bmRead);
PDFView1->OpenMem( (short*)stream,stream->Size ,NULL ) ;
想请教高手,上面的代码应该如下写,才能正确实现从数据库字段----内存中流------控件中呢?
3 个解决方案
#1
OpenDialog1->InitialDir =".\\" ; //初始化打开对话框读图片的例子,应该跟你的差不多吧,你先试试看看啊
OpenDialog1->Filter = "旅客信息文件 (*.mdb)|*.mdb|所有文件 (*.*)|*.*";
OpenDialog1->DefaultExt = String("mdb");
if(OpenDialog1->Execute ())//动态指定数据源
{
AnsiString ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password = GoldenShield;Data Source = " + OpenDialog1->FileName.Trim ();
ADOQuery1->ConnectionString = ConnStr.Trim ();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from cguester");
ADOQuery1->Open();
TBlobField * pField=(TBlobField *)ADOQuery1->FieldByName("DJ_ZHAOPIAN");
TADOBlobStream* pmem=new TADOBlobStream (pField,bmRead);
pmem->Seek(0,soFromBeginning);
TJPEGImage *pBitmap = new TJPEGImage();
//Graphics::TJPEGImage * pBitmap=new Graphics::TJPEGImage();
pBitmap->LoadFromStream(pmem);
Image1->Picture->Assign(pBitmap);
delete pBitmap;
delete pmem;
#2
不行,和我的代码报错一样
#3
写入流
设置流的位置为0
读取流
设置流的位置为0
读取流
#1
OpenDialog1->InitialDir =".\\" ; //初始化打开对话框读图片的例子,应该跟你的差不多吧,你先试试看看啊
OpenDialog1->Filter = "旅客信息文件 (*.mdb)|*.mdb|所有文件 (*.*)|*.*";
OpenDialog1->DefaultExt = String("mdb");
if(OpenDialog1->Execute ())//动态指定数据源
{
AnsiString ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password = GoldenShield;Data Source = " + OpenDialog1->FileName.Trim ();
ADOQuery1->ConnectionString = ConnStr.Trim ();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from cguester");
ADOQuery1->Open();
TBlobField * pField=(TBlobField *)ADOQuery1->FieldByName("DJ_ZHAOPIAN");
TADOBlobStream* pmem=new TADOBlobStream (pField,bmRead);
pmem->Seek(0,soFromBeginning);
TJPEGImage *pBitmap = new TJPEGImage();
//Graphics::TJPEGImage * pBitmap=new Graphics::TJPEGImage();
pBitmap->LoadFromStream(pmem);
Image1->Picture->Assign(pBitmap);
delete pBitmap;
delete pmem;
#2
不行,和我的代码报错一样
#3
写入流
设置流的位置为0
读取流
设置流的位置为0
读取流