2

To read image metadata, the basic process I know is as follows:

  • Read the whole file from its path ([image_path]):
   Dim ImScan = Image.FromStream(New IO.MemoryStream(IO.File.ReadAllBytes([image_path])))
  • Get the desired metadata characterized by its ID ([PropItem_ID]) with the GetPropertyItem function as :
    Dim propItem As Imaging.PropertyItem = ImScan.GetPropertyItem([PropItem_ID])

Performance problems appear with this workflow when you need to parse through a large number of images. Loading the entire file for each image just to grab a small part of information seems to be non-optimized and shows rather poor performance.

Is there a way to read the metadata part of an image file only? I did not find any relevant methods in the System.IO.File class.

Thanks for your support.

Sulli
  • 45
  • 4
  • Try [this](https://stackoverflow.com/a/9687096/14171304). Also, see the other answers. – dr.null Apr 22 '21 at 22:01
  • 1
    If you don't need to show the Images anywhere, just setting `Dim ImScan = Image.FromStream(New IO.MemoryStream(IO.File.ReadAllBytes([image_path])), False, False)` will perform better. If you need to show the Images, set the first `False` argument to `True`. You can use `Directory.EnumerateFiles()` instead of `Directory.GetFiles()` and perform the *extraction* while the enumeration yields its results. After that, it depends on what kind of hardware you find and whether the Images are located in different drives. If it's a single magnetic drive (moving heads), not much else, except caching. – Jimi Apr 22 '21 at 22:18
  • You mention "Loading the complete image each time" - to avoid the *each time* you could store the metadata in a database and update that if the file's last-modified timestamp has changed. – Andrew Morton Apr 23 '21 at 21:35
  • Faster = Binary Reading... That's why I asked you to read the other answers. The accepted one for example. Reading images data requires understanding the specification of each format to know where exactly you should dig. See the [PNG](https://www.w3.org/TR/2003/REC-PNG-20031110/) specification for example. – dr.null Apr 23 '21 at 21:51
  • @Andrew Morton: I rephrased as "Loading the entire file for each image" to avoid misunderstanding. – Sulli Apr 23 '21 at 22:10
  • 1
    @dr.null: I read carefully what you suggest and that's the right way to go. As you mention, reading images data requires understanding the specification of each format. I am currently dealing with JPG and PNG and I have to further look into those format specifications.However, I would have believed there exist somehow "turnkey" solutions. – Sulli Apr 23 '21 at 22:10

0 Answers0