Jpeg in TDBImage

Jpeg in TDBImage

Post by G. Scott Leak » Thu, 11 Mar 1999 04:00:00



I have a form that allows a user to pick an image (usually JPeg) to
associate with a particular record.  I added the JPeg unit to the uses
clause of the unit.  It selects and displays the image just fine (using
TDBImage.Picture.LoadFromFile).  It saves it to the database blob field just
fine as well.  When I try to select the record and have the TDBImage control
display the image, I get a "Bitmap image is not valid."

Anybody give me some help on this?  I have been staring at it WAY too long.

Thanks.

 
 
 

Jpeg in TDBImage

Post by Graham Stratfor » Fri, 12 Mar 1999 04:00:00


The TDBImage control can only retrieve a TBitmap from your database. To
get a JPEG out, you will have to create a TJPEGImage, load from the
database using a TBlobStream, then do TImage.Assign on a NORMAL TImage.

I may be wrong (someone please correct me if I am), but I think the
easiest place to do this would be on your TTable's OnAfterScroll event.

Graham Stratford


> I have a form that allows a user to pick an image (usually JPeg) to
> associate with a particular record.  I added the JPeg unit to the uses
> clause of the unit.  It selects and displays the image just fine (using
> TDBImage.Picture.LoadFromFile).  It saves it to the database blob field just
> fine as well.  When I try to select the record and have the TDBImage control
> display the image, I get a "Bitmap image is not valid."

> Anybody give me some help on this?  I have been staring at it WAY too long.

> Thanks.


 
 
 

Jpeg in TDBImage

Post by Davie Ree » Fri, 12 Mar 1999 04:00:00


Since I don't see your code that your are staring at I will just make a blind
guess. Maybe you are using the blob reading as a bitmap. Maybe you should
indicate that it will be a JPG before reading the file?
Davie

> I have a form that allows a user to pick an image (usually JPeg) to
> associate with a particular record.  I added the JPeg unit to the uses
> clause of the unit.  It selects and displays the image just fine (using
> TDBImage.Picture.LoadFromFile).  It saves it to the database blob field just
> fine as well.  When I try to select the record and have the TDBImage control
> display the image, I get a "Bitmap image is not valid."

> Anybody give me some help on this?  I have been staring at it WAY too long.

> Thanks.

 
 
 

Jpeg in TDBImage

Post by Luiz Marqu » Sat, 13 Mar 1999 04:00:00



Quote:>I have a form that allows a user to pick an image (usually JPeg) to
>associate with a particular record.  I added the JPeg unit to the uses
>clause of the unit.  It selects and displays the image just fine (using
>TDBImage.Picture.LoadFromFile).  It saves it to the database blob field just
>fine as well.  When I try to select the record and have the TDBImage control
>display the image, I get a "Bitmap image is not valid."

>Anybody give me some help on this?  I have been staring at it WAY too long.

   I've got an example on how to do that on my page at
http://www.stg.com.br/soft (dbjpg).

_________________________________________________________

[Remove nospam]
Starglider Systems
_________________________________________________________

 
 
 

Jpeg in TDBImage

Post by G. Scott Leak » Sat, 13 Mar 1999 04:00:00


Ok, here is what I am trying to do now.

var
  JPegStream: TBLOBStream;
  JPegImage: TJPegImage;
  JPegField: TBlobField;

begin
      // TDBImage can't handle JPeg, so need to stream it in to component
      if (not (dsManufacturer.FieldByName('Image').IsBlob)) then
      begin
        dbimgManufacturer.Picture := nil;
      end
      else
      begin
        JPegField :=
TBlobField(wwdatasetImageManufacturer.FieldByName('Image'));
        JPegStream := TBLOBStream.Create(JPegField, bmRead);
        JPegImage := TJPegImage.Create;

        try
          JPegImage.LoadFromStream(JPegStream);
          dbimgManufacturer.Picture.Assign(JPegImage);
        finally
          JPegStream.Free;
          JPegImage.Free;
        end;
      end;
end;

From everything I have heard and read, this should work.  But when it gets
to the 'JPegStream := ...' line, I get a message 'Invalid class typecast.'.
The cast in the line before works just fine, but the BlobStream doesn't like
it.  Any ideas?


>Since I don't see your code that your are staring at I will just make a
blind
>guess. Maybe you are using the blob reading as a bitmap. Maybe you should
>indicate that it will be a JPG before reading the file?
>Davie


>> I have a form that allows a user to pick an image (usually JPeg) to
>> associate with a particular record.  I added the JPeg unit to the uses
>> clause of the unit.  It selects and displays the image just fine (using
>> TDBImage.Picture.LoadFromFile).  It saves it to the database blob field
just
>> fine as well.  When I try to select the record and have the TDBImage
control
>> display the image, I get a "Bitmap image is not valid."

>> Anybody give me some help on this?  I have been staring at it WAY too
long.

>> Thanks.

 
 
 

Jpeg in TDBImage

Post by Razvan Fechet » Sun, 14 Mar 1999 04:00:00


Try this code out. It should work.
Regards.

-------------------------------------------
 var
   JPegStream: TBLOBStream;
   JPegImage: TJPegImage;
//   JPegField: TBlobField;  - leave this variable out, you don't need it

 begin
       // TDBImage can't handle JPeg, so need to stream it in to component
       if (not (dsManufacturer.FieldByName('Image').IsBlob)) then
       begin
         dbimgManufacturer.Picture := nil;
       end
       else
       begin
         JPegStream :=
TBlobStream.Create(TBlobField(wwdatasetImageManufacturer.FieldByName('Image'
)),bmRead);
         JPegImage := TJPegImage.Create;

         try
           JPegImage.LoadFromStream(JPegStream);
           dbimgManufacturer.Picture.Graphic:=TJpegImage(JpegImage);

         finally
           JPegStream.Free;
           JPegImage.Free;
         end;
       end;
 end;