ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Saving Thumbnails and EXIF Data in a Database
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

JimMellish

United Kingdom
7 Posts

Posted - Jun 01 2017 :  10:06:33  Show Profile  Reply
Hi,

I need to store thumbnails and some exif data for a list of files in a database. No visual representation of the images is required.

I need a TIEBitmap to create the thumbnail using Resample and I need a TImageEnIO so I can use SaveToStream to save the thumbnail in the database. The only way I could get this to work is shown below.

try
  IEBmp := TIEBitmap.Create;
  ImageEnIO := TImageEnIO.CreateFromBitmap(IEBmp);

  for i := 0 to Length(Vec) - 1 do
    begin
      ImageEnIO.LoadFromFile(Vec[i]);

      IEBmp.Resample (100, 100, rfFastLinear, True);
      { ... Create blob field and write thumbnail to database ... }

      ImageEnIO.ParamsFromFile(Vec[i]);
      { ... Write exif data to database ... } 
    end;

finally
  FreeAndNil(ImageEnIO);
  FreeAndNil(IEBmp);
end;

I appears that I am reading the image file from disk twice, once to load the image and once to load the exif data. I have been going round in circles using different combinations of TIEBitmap, TImageEnIO and TIOParams to try and reduce the number of disk reads to one but can't get anything to work. Is there a better way of doing this ?

Jim

xequte

38613 Posts

Posted - Jun 01 2017 :  16:51:25  Show Profile  Reply
Hi Jim

There are a few issues here:

1. You call ParamsFromFile after LoadFromFile. ParamsFromFile is the same as LoadFromFile but skips the image loading, so you don't need it.

2. You need to be aware of your Params object (the class that stores all of the EXIF and other meta-data). In your code below you are using the ImageEnIO.Params. You can optionally use the IEBmp.Params if you call IEBmp.ParamsEnabled := True.

3. Why not use the TIEDBBitmap class? It is a TIEBitmap with DB support:

https://www.imageen.com/help/TIEDBBitmap.html


In the code below, you don't need the ImageEnIO because TIEBitmap supports stream saving anyway (though it doesn't hurt).

Here's an example:

// Append a thumbnail to the database (with its meta-data)
MyBMP := TIEDBBitmap.Create();
MyBMP.ParamsEnabled := True; // So bitmap stores the params
MyBMP.Read( 'D:\MyBlobImage.jpeg' );
IEBmp.Resample (100, 100, rfFastLinear, True); // Convert to thumbnail
MyTable.Append;
MyTableName.AsString := 'My Thumbnail';
MyBmp.Write( MyTableImageBlob, ioJPEG );
MyTable.Post;
MyBmp.Free;




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

JimMellish

United Kingdom
7 Posts

Posted - Jun 02 2017 :  11:08:39  Show Profile  Reply
Hi Nigel,

Thanks for the reply. I didn't use TIEDBBitmap because ... I didn't know it was there. Everything is now working well.

Jim
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: