C++ Builder 下 SQL SERVER image(图片)字段的存取。
在csdn以及手册中找来。
只记录关键代码备查。
找的好苦,看来有必要看看VCL了。
注:如使用jpeg图片需要包含Jpeg.hpp头文件。
写入
Code: |
ADOQuery1->Append(); TBlobField *Field = (TBlobField*)ADOQuery1->FieldByName("img"); if(OpenPictureDialog1->Execute()) { Field->LoadFromFile(OpenPictureDialog1->FileName); ADOQuery1->Post(); } |
读取
Code: |
TMemoryStream *tmps = new TMemoryStream(); TBlobField *Field = (TBlobField*)ADOQuery1->FieldByName("img"); Field->SaveToStream(tmps); if(tmps->Size>0) { TJPEGImage *tjp = new TJPEGImage(); tmps->Seek(0, soFromBeginning); tjp->LoadFromStream(tmps); Image1->Picture->Bitmap->Assign(tjp); delete tjp; } delete tmps; |