Solved

How to convert a Blob file to image

Posted on 2003-11-28
4
727 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:mnasman
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

21 Experts available now in Live!

Get 1:1 Help Now