Link to home
Start Free TrialLog in
Avatar of Richard Teasdale
Richard TeasdaleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

blob file to image delphi

Hi: I have a paradox table with three records docno  line and image. The image is a  blob files. I am wanting to get the blob files saved as jpg or gif, with each file given the name +line  of the doc no. So record 123 line 4 becomes c:\images\1234.jpg.
I know how to do it in paradox; is there a way of doing it in delphi ? I am a novice to delphi so please be gentle!

Here is the objectpal way:
scan tc :
docno = tc."docno"
line = tc."line"
   label = docno + line
  img=tc."image" ; field containing graphic
  img.writetofile("J:\\labels\\images\\" + label + ".jpg")
endscan


Thanks!
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

You can put TDBImage component and link to blob field - image should show on row scroll.
For loading/saving blobs - go to similar EE questions - there are few good code examples:
Q_28523636,Q_28163858
Avatar of Richard Teasdale

ASKER

Sorry for the delay in replying, and thank you Sinisa.  Below is as far as I get; for only one record in the table. There is a file produced but it is unreadable in paint. Can you see where I am going wrong =, please? And how to roll it out across several records, using docno + line as the file name?
 record 'Image' is the blob

procedure TForm1.Button5Click(Sender: TObject);
var
  Blob: TBlobStream;
  Strm: TFileStream;
begin
  Query3.SQL.Text := 'SELECT docno, line, image FROM "blob.DB" where docno = 52215 and line = 1 ';
  Query3.Open;
  Blob := Query3.CreateBlobStream(Query3.Fields[2], bmRead) as TBlobStream;
  try
    Strm := TFileStream.Create('s:\labels\images\test.jpg', fmCreate);
    try
      Strm.CopyFrom(Blob, Blob.Size);
    finally
      Strm.Free;
    end;
  finally
    Blob.Free;
  end;
end;
can you post this test.jpg here. maybe I can find out from it.
alternatively check this:
...
Query3.Open;
    Strm := TFileStream.Create('s:\labels\images\test.jpg', fmCreate);
    try
      (Query3.FieldByName('image') AS TBlobField).SaveToStream(Strm);
    finally
      Strm.Free;
    end;

Open in new window

Thank you very much SInisa.
Here the code I have just run:

procedure TForm1.Button6Click(Sender: TObject);
 var
  Blob: TBlobStream;
  Strm: TFileStream;
begin
 Query3.SQL.Text := 'SELECT docno, line, image FROM "blob.DB" ';
  Query3.Open;
    Strm := TFileStream.Create('s:\labels\images\test.jpg', fmCreate);
    try
      (Query3.FieldByName('image') AS TBlobField).SaveToStream(Strm);
    finally
      Strm.Free;
    end;
end;
test.jpg
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much Sinisa!
Perfect.  Thank you for your patience, too!