Solved

How to convert a Blob file to image

Posted on 2003-11-28
4
728 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now