Solved

How to convert a Blob file to image

Posted on 2003-11-28
4
730 Views
Last Modified: 2010-04-05
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?
0
Comment
Question by:goldragon
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
TheLeader earned 50 total points
ID: 9841340
0
 
LVL 2

Expert Comment

by:TheLeader
ID: 9841354
even if you would like components
http://www.torry.net/db_images.htm
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 9841715
Hello

if you add the fields using field editor, you can use
Table1MyBlobField.SaveToFile('c:\myimg.bmp');

or
TBlobField(Table1['MyBLobField']).SaveToFile('c:\myimg.bmp');

0
 
LVL 9

Expert Comment

by:mocarts
ID: 9843100
from question asked few days ago... (!)
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20810387.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.CreateBlobStream(aField, 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(GetGraphicFromBlob(TBlobField(FieldByName('img'))));
    finally
      close;
    end;
  end;
end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question