Richard Teasdale
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:\\label s\\images\ \" + label + ".jpg")
endscan
Thanks!
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:\\label
endscan
Thanks!
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(Qu ery3.Field s[2], bmRead) as TBlobStream;
try
Strm := TFileStream.Create('s:\lab els\images \test.jpg' , fmCreate);
try
Strm.CopyFrom(Blob, Blob.Size);
finally
Strm.Free;
end;
finally
Blob.Free;
end;
end;
record 'Image' is the blob
procedure TForm1.Button5Click(Sender
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(Qu
try
Strm := TFileStream.Create('s:\lab
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:
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;
ASKER
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:\lab els\images \test.jpg' , fmCreate);
try
(Query3.FieldByName('image ') AS TBlobField).SaveToStream(S trm);
finally
Strm.Free;
end;
end;
test.jpg
Here the code I have just run:
procedure TForm1.Button6Click(Sender
var
Blob: TBlobStream;
Strm: TFileStream;
begin
Query3.SQL.Text := 'SELECT docno, line, image FROM "blob.DB" ';
Query3.Open;
Strm := TFileStream.Create('s:\lab
try
(Query3.FieldByName('image
finally
Strm.Free;
end;
end;
test.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much Sinisa!
Perfect. Thank you for your patience, too!
Perfect. Thank you for your patience, too!
For loading/saving blobs - go to similar EE questions - there are few good code examples:
Q_28523636,Q_28163858