图片存入oracle 数据 库的blob字段:
// 把Image1显示的图片写入到Employee表的Photo字段
Query1->RequestLive = true;
Query1->SQL->Clear();
Query1->SQL->Add("SELECT Photo FROM Employee WHERE Id = :Id");
Query1->Prepare();
Query1->Params->Items[0]->AsString = "0001";
Query1->Open();
Query1->Edit();
if (Image1->Picture->Graphic)
{
TBlobStream *Stream = new TBlobStream( (TBlobField *)Query1->FieldByName("Photo"),
bmReadWrite );
Stream->Seek(0, soFromBeginning);
try
{
Image1->Picture->Bitmap->SaveToStream(Stream);
}
__finally
{
delete Stream;
}
}
else
((TBlobField *)Query1->FieldByName("Photo"))->Clear();
Query1->Post();
Query1->Close();
Query1->UnPrepare();
Query1->RequestLive = false;
// 方法1
if (!((TGraphicField *)Query1->FieldByName("Photo"))->IsNull)
Image1->Picture->Assign((TGraphicField *)Query1->FieldByName("Photo"));
else
Image1->Picture = NULL;
// 方法2
TBlobStream *Stream = new TBlobStream( (TBlobField *)Query1->FieldByName("Photo"),
bmRead );
Stream->Seek(0, soFromBeginning);
if (Stream->Size > 0)
Image1->Picture->Bitmap->LoadFromStream(Stream);
else
Image1->Picture = NULL;
delete Stream;