Board index » delphi » Putting JPG or GIF Images into a database

Putting JPG or GIF Images into a database

Hi,

I'm using D3 with Paradox databases.
I need to insert JPG or GIF Images into a Database field.

Can it be done??

Is there a third party component that will do it??

Thanks,

Frank
--------------------

 

Re:Putting JPG or GIF Images into a database


Frank,

Table1Graphic is a persistent field type, you could use
Table1.FieldByName('Graphic') instead. You can not use the TDBImage
control, the code below shows how to use a TImage in a TDatasource
OnDataChange handler instead.
To load/view GIF images it's the same basic code except that there is
no inbuilt support for GIF files in Delphi. Anders Melander has a
freeware component to do the conversions (its www.melander.com I
think.)

If you are going to mix JPegs and GIFs then you have to be able to
identify what the Blob field contains. The simplest method is to carry
the file extension in a separate field, although it should be possible
to interrogate the file header in the stream. Something I have not got
round to.

//Load jpeg in file to blob field
procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute then
  with Table1 do begin
    Append;
    Table1Graphic.LoadFromFile(OpenPictureDialog1.Filename);
    Post;
  end;
end;
//View JPeg in Blob field
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
var
  jpg:TJpegImage;
  memStream:TMemoryStream;
begin
  memStream:=TMemoryStream.Create;
  try
    jpg:=TJpegImage.Create;
    try
      if not Table1Graphic.IsNull then begin
        Table1Graphic.SaveToStream(memStream);
        memStream.Seek(0,0);
        jpg.LoadFromStream(memStream);
        Image1.Picture.Assign(jpg);
      end;
    finally
      jpg.free;
    end;
  finally
    memStream.free;
  end;
end;

Don't forget to put "JPeg" in the uses clause.

Bob
---
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:Putting JPG or GIF Images into a database


Quote
>I'm using D3 with Paradox databases.
>I need to insert JPG or GIF Images into a Database field.

>Can it be done??

What form are then in when you need to store them?   if they are files you can
store them in a Blob field using the TblobField.loadFromFile method.
If you don't have these in file form then some more information on what you are
trying to do would be helpful.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Putting JPG or GIF Images into a database


Quote
> freeware component to do the conversions (its www.melander.com I
> think.)

Correction: www.melander.dk

Re:Putting JPG or GIF Images into a database


Can a paradox table store Gif or Jpeg images directly?  I am using Delphi
4.

Quote
>What form are then in when you need to store them?   if they are files you
can
>store them in a Blob field using the TblobField.loadFromFile method.
>If you don't have these in file form then some more information on what
you are
>trying to do would be helpful.

>--
>Brian Bushay (TeamB)
>Bbus...@NMPLS.com

Re:Putting JPG or GIF Images into a database


Please ignore this thread.  I found the answer in previous discussion.

Desmond

Re:Putting JPG or GIF Images into a database


Please ignore this thread.  I found the answer in previous discussion.

Desmond

Re:Putting JPG or GIF Images into a database


If you are using the graphic field in your paradox tables you can use code
like the following.
To get support for Jpeg's add "JPEG" to your uses clause in your unit, for
GIF support I suggest The TGIFImage component found here
http://www.melander.dk/delphi/gifimage/

You load the image into a picture to handle any graphic type, then pass it
through a TBitmap for conversion on its way into the TField object.
procedure TForm_Images.SpeedButton_GetPicClick(Sender: TObject);
Var
  Image: TImage;
  Bitmap: TBitmap;
begin
  If OpenDialog.Execute then
    Begin
      Image := TImage.Create(Self);
      Bitmap := TBitmap.Create;
      Image.Picture.LoadFromFile(OpenDialog.FileName);
      Bitmap.Assign(Image.Picture.Graphic);
      Table_ImagesData.Assign(Bitmap);
    end;
  Image.Free;
  Bitmap.Free;
end;

Hope this helps
Michael Gallaher
m...@asipay.com

Quote
Frank Fortino <ffort...@svn.net> wrote in message

news:39A6993C.2DF891EF@svn.net...
Quote
> Hi,

> I'm using D3 with Paradox databases.
> I need to insert JPG or GIF Images into a Database field.

> Can it be done??

> Is there a third party component that will do it??

> Thanks,

> Frank
> --------------------

Re:Putting JPG or GIF Images into a database


Michael,

Although you can use the TDBImage by converting JPeg to Bitmap and
storing the bitmap in a graphic field, you are throwing away one
almighty advantage of the JPeg format, namely that it is highly
compressed.
That's about ten times the network traffic and ten times the data
storage, which is a big price IMO for a small programming advantage.

Bob
---
Sent using Virtual Access 5.01 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:Putting JPG or GIF Images into a database


Bob,

Your are correct of course, using a BLOB field, would allow me to store
jpeg, or gif, or any other file type in its native format, and take full
advantage of features like compression, or animation, as well as reduce
traffic in a network environment.

The client is using the application in a non network environment, and one of
the reporting tools used will only handle bitmaps, so this was the solution.

Thanks for your comments.
Michael Gallaher
m...@asipay.com

Quote
Bob Villiers <bob_villi...@lineone.net> wrote in message

news:VA.000000bf.00e2a399@lineone.net...
Quote
> Michael,

> Although you can use the TDBImage by converting JPeg to Bitmap and
> storing the bitmap in a graphic field, you are throwing away one
> almighty advantage of the JPeg format, namely that it is highly
> compressed.

> That's about ten times the network traffic and ten times the data
> storage, which is a big price IMO for a small programming advantage.

> Bob
> ---
> Sent using Virtual Access 5.01 - download your freeware copy now
> http://www.atlantic-coast.com/downloads/vasetup.exe

Other Threads