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!
Richard TeasdaleFinancial ControllerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
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
Richard TeasdaleFinancial ControllerAuthor Commented:
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;
Sinisa VukSoftware architectCommented:
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

Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Richard TeasdaleFinancial ControllerAuthor Commented:
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
Sinisa VukSoftware architectCommented:
As I thought.... this blob is encoded somehow... I Delete first 8 bytes, until 'BM' (hexeditor)
and seems that this is a Bitmap not jpeg file. This truncation can be done using Blob stream as you do first time:
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
    Blob.Seek(8, soFromBeginning); //skip size??
    Strm := TFileStream.Create('s:\labels\images\test.bmp', fmCreate);
    try
      Strm.CopyFrom(Blob, Blob.Size - 8);
    finally
      Strm.Free;
    end;
  finally
    Blob.Free;
  end;
end; 

Open in new window

test2.bmp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard TeasdaleFinancial ControllerAuthor Commented:
Thank you very much Sinisa!
Perfect.  Thank you for your patience, too!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.