insert picture

srisha
srisha used Ask the Experts™
on
How to insert picture onto a table in delphi(No SQL please)?show with examples
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
Commented:
to insert

TBLobField(Dataset.FieldByName('FieldName')).LoadFromFile('PictureFileName');

to extract

TBLobField(Dataset.FieldByName('FieldName')).SaveToFile('PictureFileName');

meikl ;-)
Try this code here. This is assuming you already have a Table1 open (TADOTable component). The first procedure is to write and the second to read... Make sure the information you store is compatible with the one you read... ex: Don't try to read a JPEG with a TBitmap. Let me know if you need to convert image I might have some nice and simple stuff here for you...


procedure TForm2.WriteImageToDB();
var
  ST: TStream;

begin
  with Table1 do begin
    Edit;
    ST := CreateBlobStream(FieldByName('ImageField'), bmWrite);
    try
      Image1.Picture.Bitmap.SaveToStream(ST);
    finally
      ST.Free;
      Post;
    end;
  end;
end;

//Assuming that you already have a Table open...
procedure TForm2.ReadImageFromDB();
var
  ST: TStream;

begin
  with Table1 do begin
    ST := CreateBlobStream(FieldByName('ImageField'), bmRead);
    try
      Image1.Picture.Bitmap.LoadFromStream(ST);
    finally
      ST.Free;
    end;
  end;
end;

Commented:
here a program which insert picture from clib board to table. My DBImage is connected to Image(Blob Type)Field in Table.

procedure TForm1.BitBtn1Click(Sender: TObject);
var
 cb: TClipboard;
begin

     cb := TClipboard.Create;
     try
       if Clipboard.HasFormat(CF_BITMAP) then begin
          Table1.Open;      
          DBImage1.PasteFromClipboard;
          Table1.Post;
          end
       else
          ShowMessage('Clipboard does not contain a any Bitmap Image!');
     finally
       cb.Free;
     end;

end;
srisha:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial