gif/jpg picture formats for TDBImage compo format in

Can Any one tell me how to store jpg/gif files in dbImage component n a paradox/ dbase table?Are there any components to do the job.I am that you can load a TImage component with jpg/gif if RX library
is installed?But how to do the same thing for TDBImage component
Thanks
vebks
LVL 1
venksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi venks,

use a normal timage and some code like this.
its recommend to use a binary-blobfield and not a graphic-blobfield in the database.
this sample uses the freeware component gifimage,
but you can use any other gif-component
(maybe then there a some little modifications on the code to do)


unit db_picture_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtDlgs, Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask,
  Jpeg,  //Jpeg-Unit used
  GifUnit, ComCtrls;  // Gif-Unit used

type
  TForm1 = class(TForm)
    Image1: TImage;  //db-navigation
    Table1: TTable;              //the table, where the images are stored
    DataSource1: TDataSource;
    OpenPictureDialog1: TOpenPictureDialog;
    Panel1: TPanel;
    ProgressBar1: TProgressBar;
    DBNavigator1: TDBNavigator;
    Button1: TButton;
    Panel2: TPanel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject); //execute load and preStore to the Blobfield
    procedure FormCreate(Sender: TObject);   //TableOpen
    procedure FormDestroy(Sender: TObject);  //TableClose
    procedure Table1AfterScroll(DataSet: TDataSet);
    procedure Table1BeforeScroll(DataSet: TDataSet);
    procedure Image1Progress(Sender: TObject; Stage: TProgressStage;
      PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: String);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
  ExtS : String[4];  //Holds The Extension
begin
  if (Table1.State = dsEdit) or  (Table1.State = dsInsert) then    // Do only if in edit mode
  begin
    If openpicturedialog1.Execute then    // If file selected
    begin
      if Table1.FieldByName('Picture').IsBlob then   // this line can deleted
      begin  //remember the Extension
        ExtS := copy(AnsiUpperCase(ExtractFileExt(OpenPictureDialog1.FileName)),2,MaxLongInt);
        if ExtS = 'JPEG' then ExtS := 'JPG';  //Normalize Extension
        if (ExtS = 'JPG') or (ExtS = 'GIF') then  //If one of these extensions
        begin
          try
            TBlobField(Table1.FieldByName('Picture')).LoadFromFile(openpicturedialog1.filename);  //Store the File in the Blob
            Table1.FieldByName('Typ').AsString := ExtS; //Store the Extension in the Grafic-TypField
            image1.Picture.LoadFromFile(openpicturedialog1.filename); //Load Image, also from file
          except
            showMessage('Error during BlobOperation');
          end;
        end
        else showmessage('no jpg or gif-file selected');
      end;
    end;
  end else ShowMessage('Table is not in Edit Mode!');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Table1.Open;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Table1.Close;
end;

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
Var
  MyJpegImage : TJpegImage;
  MyGifImage : TGifFile;
  MyBlobStream : TBlobStream;
begin
  // Do Only if a Picture available
  if (Table1.FieldByName('Picture').IsBlob) and (not(Table1.FieldByName('Picture').IsNull)) then
  begin  //create a blobstream
    MyBlobStream := TBlobStream.Create(TBlobField(Table1.FieldByName('Picture')),bmRead);
    if Table1.FieldByName('Typ').Asstring = 'GIF' then  //if grafictyp = gif
    begin
      MyGifImage := TGifFile.Create;               //create GifObject, can also be done Global
      MyGifImage.LoadFromStream(MyBlobStream);     //get the information from the blob
      Image1.Picture.Assign(MyGifImage.AsBitmap);  //Display Gif
      MyGifImage.Free;                             //Free Object
    end
    else  //can only be JPG
    begin
      MyJPegImage := TJPegImage.Create;         //create JPegObject, can also be done global
      MyJPegImage.LoadFromStream(MyBlobStream); //get the information from the blob
      Image1.Picture.Assign(MyJPegImage);       //Display JPeg
      MyJPegImage.Free;                         //Free Object
    end;
    MyBlobStream.Free;  // Free Stream
  end
  else image1.Picture.assign(Nil);  // No Picture saved disable display
  screen.Cursor := crDefault;
  ProgressBar1.Position := 100;
end;

procedure TForm1.Table1BeforeScroll(DataSet: TDataSet);
begin
  screen.cursor := crhourglass;
  ProgressBar1.Position := 0;
end;

procedure TForm1.Image1Progress(Sender: TObject; Stage: TProgressStage;
  PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
  const Msg: String);
begin
  Progressbar1.Position := Percentdone;
end;


end.

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
venksAuthor Commented:
Thanks for the answer.Can you please tell me where I can download the gifiMage component
Venks
0
kretzschmarCommented:
hi venks,

thanks for accepting ;-)

well the gifimage i've used here you can get there
http://sunsite.icm.edu.pl/delphi/ftp/d10free/gifimage.zip
its an older one,

and you can get a better by
www.melander.dk  (maybe some codechanges must be done)

good luck

meikl
0
venksAuthor Commented:
Thanks
Venks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.