goldragon
asked on
How to convert a Blob file to image
Hi, How do I convert a blob image file from a database into a Timage, cos I want to grab a picture from my paradox database and display that into a Timage object on the screen with out having to use TDBimage, any suggestion?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello
if you add the fields using field editor, you can use
Table1MyBlobField.SaveToFi le('c:\myi mg.bmp');
or
TBlobField(Table1['MyBLobF ield']).Sa veToFile(' c:\myimg.b mp');
if you add the fields using field editor, you can use
Table1MyBlobField.SaveToFi
or
TBlobField(Table1['MyBLobF
from question asked few days ago... (!)
https://www.experts-exchange.com/questions/20810387/show-an-image-stored-in-a-database.html
uses jpeg;
function GetGraphicFromBlob(aField: TBlobField): TGraphic;
var
s: TStream;
buf: word;
begin
if not assigned(aField) then exit;
Result := nil;
s := aField.DataSet.CreateBlobS tream(aFie ld, bmRead);
try
if s.read(buf, sizeof(buf)) <> sizeOf(buf) then exit;
s.Position := 0;
if buf = $D8FF then
Result := TJPEGImage.Create
else if buf = $4D42 then
Result := TBitmap.Create
else if buf = $CDD7 then
Result := TMetafile.Create
else if buf = 0 then
Result := TIcon.Create;
if assigned(Result) then begin
try
Result.LoadFromStream(s);
except
Result.Free;
Result := nil;
end;
end;
finally
s.Free; // must free stream
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
var
i: integer;
begin
i := 1;
with Table1 do begin
Open;
try
// if image will not load from blob then result of getGraphicFromBlob
// will be nil and Image1 will be empty
// you can of course check result to give an error to user by using intermediate var
Image1.Picture.Assign(GetG raphicFrom Blob(TBlob Field(Fiel dByName('i mg'))));
finally
close;
end;
end;
end;
https://www.experts-exchange.com/questions/20810387/show-an-image-stored-in-a-database.html
uses jpeg;
function GetGraphicFromBlob(aField:
var
s: TStream;
buf: word;
begin
if not assigned(aField) then exit;
Result := nil;
s := aField.DataSet.CreateBlobS
try
if s.read(buf, sizeof(buf)) <> sizeOf(buf) then exit;
s.Position := 0;
if buf = $D8FF then
Result := TJPEGImage.Create
else if buf = $4D42 then
Result := TBitmap.Create
else if buf = $CDD7 then
Result := TMetafile.Create
else if buf = 0 then
Result := TIcon.Create;
if assigned(Result) then begin
try
Result.LoadFromStream(s);
except
Result.Free;
Result := nil;
end;
end;
finally
s.Free; // must free stream
end;
end;
procedure TForm1.Button1Click(Sender
var
i: integer;
begin
i := 1;
with Table1 do begin
Open;
try
// if image will not load from blob then result of getGraphicFromBlob
// will be nil and Image1 will be empty
// you can of course check result to give an error to user by using intermediate var
Image1.Picture.Assign(GetG
finally
close;
end;
end;
end;
http://www.torry.net/db_images.htm