Board index » delphi » Saving a JPEG image in a field

Saving a JPEG image in a field

Does anyone know how to save a TJpeg image to (and recall it from) a
database?
I have a Paradox table with a field named "Picture" of type binary.  Is that
a "Blob" field?
I have an image in two forms: A TJpeg image displayed on the screen, and as
a JPeg file.

I need a way to save the JPEG image to the database and then recover it.

I have tried to create a Blobstream to copy the image from the JPeg image to
the Picture field in the table, but I am unable to create the Blobstream
with this line:

        Stream2 :=
tblPicture.CreateBlobStream(tblPicture.FieldByName('Picture'), bmWrite);

but I get a compiler error:  Incompatible types: 'TBlobStream' and
'TStream'.

I tried to typecast the binary field, 'Picture' to type TBlobStream but that
did not work either.

Does anyone know how to save a Jpeg image to a database field?

Thanks

 

Re:Saving a JPEG image in a field


uses JPEG;               // this dcu file is in the delphi\Lib dir

//create a field(xxfield) in your Paradox table(xxtable) with field type
GRAPHIC

//save you JPEG file into table
xxtablexxfield.LoadFromFile('YourJpegFile.Jpg');

//Load from xxfield and save it into 'YourJpegFile.Jpg'
Var FileStream: TFileStream;
      BlobStream: TBlobStream;
Begin
    BlobStream := TBlobStream.Create(xxtablexxfield,bmRead);
    if BlobStream.Size=0 then begin BlobStream.Free; Exit; end
    else Begin
     FileStream := TFileStream.Create('YourJpegFile.Jpg',fmCreate or
fmOpenWrite);
     FileStream.CopyFrom(BlobStream, BlobStream.Size);
     FileStream.Free;
     BlobStream.Free;
    end;
end;

-------------------------------------
Frankie Leong

Phil Edwards <p...@cicom.net> wrote in article
<6tuh0k$kv...@scoop.suba.com>...

Quote
> Does anyone know how to save a TJpeg image to (and recall it from) a
> database?
> I have a Paradox table with a field named "Picture" of type binary.  Is
that
> a "Blob" field?
> I have an image in two forms: A TJpeg image displayed on the screen, and
as
> a JPeg file.

> I need a way to save the JPEG image to the database and then recover it.

> I have tried to create a Blobstream to copy the image from the JPeg image
to
> the Picture field in the table, but I am unable to create the Blobstream
> with this line:

>         Stream2 :=
> tblPicture.CreateBlobStream(tblPicture.FieldByName('Picture'), bmWrite);

> but I get a compiler error:  Incompatible types: 'TBlobStream' and
> 'TStream'.

> I tried to typecast the binary field, 'Picture' to type TBlobStream but
that
> did not work either.

> Does anyone know how to save a Jpeg image to a database field?

> Thanks

Re:Saving a JPEG image in a field


Quote
Phil Edwards <p...@cicom.net> wrote:
> I have tried to create a Blobstream to copy the image from the JPeg image
to
> the Picture field in the table, but I am unable to create the Blobstream
> with this line:

>         Stream2 :=
> tblPicture.CreateBlobStream(tblPicture.FieldByName('Picture'), bmWrite);

> but I get a compiler error:  Incompatible types: 'TBlobStream' and
> 'TStream'.

> I tried to typecast the binary field, 'Picture' to type TBlobStream but
that
> did not work either.

As I understood, you declared
        var Stream2 : TBlobStream;
But the method TBDEDataSet.CreateBlobStream(...) returns TStream object,
 which cannot be saved in TBlobStream variable !!!
It's because TBlobStream is higher in hierarchy tree (in other words, it is
derived from TStream)..
Just declare
        var Stream2 : TStream ;
and then use it.

Or, alternatively, use TBlobStream.Create(Field: TBlobField; Mode:
TBlobStreamMode).

Good luck,
 Yuri Solo.

Other Threads