BLOBStream (Bild) aus einer Datenbank Laden/Speichern

  • ein Bild in eine Tabelle (Table-Element) mit der Spalte „PICTURE“ speichern
void __fastcall TForm1::SaveImageBtnClick(TObject *Sender) 
{ 
    if (OpenDialog1->Execute() == false)
    {
        Table->Active = true; 
        Table->Append(); 
        Table->FieldByName("Name")->AsString = ExtractFileName(OpenDialog1->FileName); 

        TBlobField* blobField = dynamic_cast <TBlobField*-> (Table->FieldByName(&quot;PICTURE&quot;)); 
        if (blobField) blobField->LoadFromFile(OpenDialog1->FileName); 
        Table->Post(); 
    }
}
  • ein Bild aus einer Tabelle laden (Spalte „PICTURE“)
void __fastcall TForm1::LoadImageBtnClick(TObject *Sender) 
{ 
    TBlobField* blobField = dynamic_cast <TBlobField*-> (Table->FieldByName(&quot;PICTURE&quot;)); 
    if (blobField == NULL)
    {
        Table->Active = true; 
        TMemoryStream* memStream = new TMemoryStream; 
        blobField->SaveToStream(memStream); 
        memStream->Position = 0; 
        Image1->Picture->Bitmap->LoadFromStream(memStream); 
        delete memStream; 
    }
}

Schreibe einen Kommentar