Subject RE: [ib-support] Inserting GIF into database field
Author Rado Benc
Hi Junior,

> How could I insert a GIF file into the database field? I tried to save
> with:

I use the code below to insert images (several typese) to my database.

procedure TFormMain.ActionAddExecute(Sender: TObject);
var
ExtStr: String;
ImageBmp: TImage;
ImageJpeg: TJpegImage;
ImageType: Integer;
begin
with OpenPictureDialog do
begin
if Execute then
try
ExtStr := UpperCase(ExtractFileExt(FileName));
if ExtStr = '.BMP' then
begin
ImageBmp := TImage.Create(Self);
ImageJpeg := TJpegImage.Create;
try
ImageBmp.Picture.LoadFromFile(FileName);
ImageJpeg.Assign(ImageBmp.Picture.Bitmap);
FileName := ChangeFileExt(FileName, '.jpg');
ImageJpeg.SaveToFile(FileName);
finally
ImageJpeg.Free;
ImageBmp.Free;
end;
end;
QueryImage.Last;
QueryImage.Insert;
QueryImageIMAGE_ID.AsString := FileName;
QueryImageIMAGE_DATA.LoadFromFile(FileName);
QueryImageORIGINAL_NAME.AsString := FileName;
if (ExtStr = '.JPEG') or (ExtStr = '.JPE') or (ExtStr = '.JPG') or
(ExtStr = '.BMP') then
ImageType := 1;
if ExtStr = '.GIF' then
ImageType := 2;
if (ExtStr = '.AVI') then
ImageType := 3;
if (ExtStr = '.MPG') or (ExtStr = '.MPEG') then
ImageType := 4;
if (ExtStr = '.QT') then
ImageType := 5;
QueryImageIMAGE_TYPE.AsInteger := ImageType;
QueryImage.Post;
LoadImage(ImageType);
except
raise;
end;
RefreshQuery;
end;
end;

QueryImage is an instance of TQuery with persistent fields.

QueryImageDATA is s TBlobField, QueryImageID is a string
and QueryImageIMAGE_TYPE indicates the type of the image.
LoadImage() is a method that loads and displays the image in
a TImage component.

HTH,

Rado