storing a TImage in a LONG RAW field

vkattila

Member
I would like to store and retreave a TImage in / from a LONG RAW field

I use following code for storing the image :

stream := TMemoryStream.Create;
image_travail.Picture.Graphic.SaveToStream(stream);
GetMem(buffer, stream.Size);
stream.Seek(0, soFromBeginning);
size := stream.Read(buffer^, stream.Size);
...
query.SetLongVariable('p_image', buffer, size);
...

This seems to work fine... but I'm having trouble reading the field and storing the image into a TImage.

I tried to use GetLongField (btw, how can I know the size of the picture ?) and TGraphic.LoadFromStream, but I'm not getting anywhere.

Has anybody got a source code of a working example?

Thanks a lot
Attila Kr
 
I'm not sure how to write it to an image, but if you don't know the size of the data, you can simply use the Field function. It will return a variant array of bytes, which will contain all the data.

When writing to a TStream, you can use the GetLongField function to write subsequent pieces. The function will return the number of bytes that were actually retrieved, and if it's less than the number of requested bytes, you are finished.

------------------
Marco Kalter
Allround Automations
 
Back
Top