Loading Bitmaps from Database

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
guenter1978
Posts: 9
Joined: Fri 10 Nov 2006 12:01

Loading Bitmaps from Database

Post by guenter1978 » Fri 10 Nov 2006 12:22

Hello,

I have following problem. I am trying to convert an application which currently using BDE to SDAC 3.80 components (demo version). If I get this running we will buy them.

I have further used a BDE TQuery to retrieve the Picture.

Code: Select all

lBlobStream := TBlobStream.Create(TBlobField(FieldByName('FLAG')),
						bmREAD);
try
   lBitMap := Graphics.TBitMap.Create;
   lBitMap .PixelFormat := pf4bit;
   lBitMap .TransparentMode := tmAuto;
   lBitMap .Transparent := true;
   lBitmap.LoadFromStream(lBlobStream);
finally
   lBlobStream.Free;
end;
This code worked no longer, I got messages like unsupported type conversions. Original Message is in German "Ungültige Typumwandlung".

I modified the code to following

Code: Select all

lStream := TMemoryStream.Create;
try
   TBlob(FieldByName('FLAG')).SaveToStream(lStream);
   lBitMap := Graphics.TBitMap.Create;
   lBitMap .PixelFormat := pf4bit;
   lBitMap .TransparentMode := tmAuto;
   lBitMap .Transparent := true;
   lBitmap.LoadFromStream(lStream);
finally
  lStream.Free;
end;
This code does not supply the message, as the code above, but sadly the stream seems to be empty and no picture is loaded from the database.

I use an SQL Server 2000 and the fieldtype in the database is of type image.

If someone help me with a hint, it would be very good for me.

guenter1978
Posts: 9
Joined: Fri 10 Nov 2006 12:01

Post by guenter1978 » Fri 10 Nov 2006 13:20

I just found the solution for my problem.

Code: Select all

lStream := TMemoryStream.Create;
try
   TBlobField(FieldByName('FLAG')).SaveToStream(lStream);
   lStream.Position := 0;
   lBitMap := Graphics.TBitMap.Create;
   lBitMap .PixelFormat := pf4bit;
   lBitMap .TransparentMode := tmAuto;
   lBitMap .Transparent := true;
   lBitmap.LoadFromStream(lStream);
finally
  lStream.Free;
end; 
I have changed the casting to TBlobField instead of TBlob and set the stream position to 0.

Post Reply