Board index » delphi » Problem Getting Images in and out of image fields

Problem Getting Images in and out of image fields

Hi,

I'm using MSSQL Server 7.0 and Delphi 5 Enterprise.
When I'm trying to retrieve the image from the Image Field using the
following line of code:
(Table1.FieldByname('sign') as TBlobField).Savetofile('c:\temp\sign.pcx');
I'm getting the EDBEngineError exception "Invalid BLOB handle in record
Buffer"
I'd tested this code with a Paradox table with the same structure and it
works pretty good...
Does anyone have any idea about this matter??

Regards,
Felix

 

Re:Problem Getting Images in and out of image fields


In article <3ce9d08b_1@dnews>, f...@mail.bpa.cu says...

Quote
> Hi,

> I'm using MSSQL Server 7.0 and Delphi 5 Enterprise.
> When I'm trying to retrieve the image from the Image Field using the
> following line of code:
> (Table1.FieldByname('sign') as TBlobField).Savetofile('c:\temp\sign.pcx');
> I'm getting the EDBEngineError exception "Invalid BLOB handle in record
> Buffer"

Use a BlobStream, something like

var BlobStream:TStream;
...

 BlobStream:=TBlobStream.Create(Table1.FieldByName('sign'),bmRead);
or construct it this way
 BlobStream:=Table1.CreateBlobStream(Table1.FieldByName('sign'),bmRead);

 try
  //access the stream here
 finally
  BlobStream.free;
 end;

-------------------------------
Paul Lambadaris
Delta Singular S.A.
mailto : p...@singular.gr
www    : http://www.singular.gr

Re:Problem Getting Images in and out of image fields


Thanx Paul, but anyway I'm having the same problem. I really don't
understand why when I try to get the content of the BLOB field to an Stream
or to a File  I'm receiving the exception of "Invalid Blob handle in source
record"... I really can't figure out what's happening...

Regards,
Felix

Quote
"Paul Lambadaris" <p...@singular.gr> wrote in message

news:MPG.175428e1fdd84f6e989780@newsgroups.borland.com...
Quote
> In article <3ce9d08b_1@dnews>, f...@mail.bpa.cu says...
> > Hi,

> > I'm using MSSQL Server 7.0 and Delphi 5 Enterprise.
> > When I'm trying to retrieve the image from the Image Field using the
> > following line of code:
> > (Table1.FieldByname('sign') as

TBlobField).Savetofile('c:\temp\sign.pcx');
Quote
> > I'm getting the EDBEngineError exception "Invalid BLOB handle in record
> > Buffer"

> Use a BlobStream, something like

> var BlobStream:TStream;
> ...

>  BlobStream:=TBlobStream.Create(Table1.FieldByName('sign'),bmRead);
> or construct it this way
>  BlobStream:=Table1.CreateBlobStream(Table1.FieldByName('sign'),bmRead);

>  try
>   file://access the stream here
>  finally
>   BlobStream.free;
>  end;

> -------------------------------
> Paul Lambadaris
> Delta Singular S.A.
> mailto : p...@singular.gr
> www    : http://www.singular.gr

Re:Problem Getting Images in and out of image fields


In article <3cead96c_2@dnews>, f...@mail.bpa.cu says...

Quote
> Thanx Paul, but anyway I'm having the same problem. I really don't
> understand why when I try to get the content of the BLOB field to an Stream
> or to a File  I'm receiving the exception of "Invalid Blob handle in source
> record"... I really can't figure out what's happening...

Just a thought: try to see the image with the Database Explorer, do you
get the same error?

-------------------------------
Paul Lambadaris
Delta Singular S.A.
mailto : p...@singular.gr
www    : http://www.singular.gr

Re:Problem Getting Images in and out of image fields


Felix,

  The following code should work for you:

type
  ImageHolder: TImage;
  tblSigTemp: TTable;
  tblSigTemp_MyImage: TBlobField;

var Path : String;
    MS: TMemoryStream;
    J1: TJPEGImage;

begin
  J1 := TJPEGImage.Create;
  MS := TMemoryStream.Create;
  tblSigTemp_MyImage.SaveToStream(MS);
  MS.Seek(0,soFromBeginning);
  with J1 do
    begin
      PixelFormat := jf24Bit;
      Scale := jsFullSize;
      Grayscale := False;
      Performance := jpBestQuality;
      ProgressiveDisplay := False;
      ProgressiveEncoding := False;
      LoadFromStream(MS);
    end;
  ImageHolder.Picture.Assign(J1);
  Path := ExtractFilePath(application.exename);
  ImageHolder.Picture.SaveToFile(Path + 'MyImage.jpg');
end;

Dave

"Flix Alberto Gonzlez Prez" <f...@mail.bpa.cu> wrote:

Quote
>Hi,

>I'm using MSSQL Server 7.0 and Delphi 5 Enterprise.
>When I'm trying to retrieve the image from the Image Field using the
>following line of code:
>(Table1.FieldByname('sign') as TBlobField).Savetofile('c:\temp\sign.pcx');
>I'm getting the EDBEngineError exception "Invalid BLOB handle in record
>Buffer"
>I'd tested this code with a Paradox table with the same structure and it
>works pretty good...
>Does anyone have any idea about this matter??

>Regards,
>Felix

Re:Problem Getting Images in and out of image fields


David,

Your solution won't  work ... I'm getting the same exception when I try to
save the field to stream:
  tblSigTemp_MyImage.SaveToStream(MS): " Invalid BLOB handle in record
Buffer"

I have tried with a Paradox table and all solutions run pretty good, but SQL
doesn't want to do his job :o).
I have to annotate that image is a PCX image not a JPG and SQL table was
imported from Paradox tables.

Thax Anyway...
Felix

Quote
"Dave Bolduc" <david.bol...@anthem.com> wrote in message

news:3cecf709$1_2@dnews...
Quote

> Felix,

>   The following code should work for you:

> type
>   ImageHolder: TImage;
>   tblSigTemp: TTable;
>   tblSigTemp_MyImage: TBlobField;

> var Path : String;
>     MS: TMemoryStream;
>     J1: TJPEGImage;

> begin
>   J1 := TJPEGImage.Create;
>   MS := TMemoryStream.Create;
>   tblSigTemp_MyImage.SaveToStream(MS);
>   MS.Seek(0,soFromBeginning);
>   with J1 do
>     begin
>       PixelFormat := jf24Bit;
>       Scale := jsFullSize;
>       Grayscale := False;
>       Performance := jpBestQuality;
>       ProgressiveDisplay := False;
>       ProgressiveEncoding := False;
>       LoadFromStream(MS);
>     end;
>   ImageHolder.Picture.Assign(J1);
>   Path := ExtractFilePath(application.exename);
>   ImageHolder.Picture.SaveToFile(Path + 'MyImage.jpg');
> end;

> Dave

> "Flix Alberto Gonzlez Prez" <f...@mail.bpa.cu> wrote:
> >Hi,

> >I'm using MSSQL Server 7.0 and Delphi 5 Enterprise.
> >When I'm trying to retrieve the image from the Image Field using the
> >following line of code:
> >(Table1.FieldByname('sign') as

TBlobField).Savetofile('c:\temp\sign.pcx');

- Show quoted text -

Quote
> >I'm getting the EDBEngineError exception "Invalid BLOB handle in record
> >Buffer"
> >I'd tested this code with a Paradox table with the same structure and it
> >works pretty good...
> >Does anyone have any idea about this matter??

> >Regards,
> >Felix

Other Threads