Link to home
Start Free TrialLog in
Avatar of clock1
clock1

asked on

How to get and write the dimensions of images on hard drive into an Access table

Have 20,000 images in C:\pictures that contains 10GB of images of various sizes.
Have a table that contains a field named "Location" that lists path of each image.
Have created a field in same table named "Dimension".
Want to determine the aspect ratio of each image based on width x height.
How can I get and store in same table the dimension of each image without crashing Access?
Avatar of Nick67
Nick67
Flag of Canada image

Start here
https://www.experts-exchange.com/articles/13779/More-Fun-with-Really-Large-High-Fidelity-Images-in-Access-Reports.html

It's fairly straight-forward
Set a reference to WIA
'need a reference to MS Windows Image Acquisition 2.0 library

Dim rs as recordset
Set rs = CurrentDb.Openrecordset("Select * from Location;")

Create an Image object
Dim Img As WIA.ImageFile

Dim ThePath as String
ThePath= rs!ThePath

do unitl rs.EOF
     'Set it to a filepath
      Img.LoadFile ThePath

    With rs
         .Edit
         !Dimension = Img.Height/Img.Width
         .Update
    End with
    Set Img = Nothing
    rs.movenext
Loop

Make sense?
Avatar of clock1
clock1

ASKER

Does rs!ThePath take the entire path listed in location?
ASKER CERTIFIED SOLUTION
Avatar of Nick67
Nick67
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clock1

ASKER

Yes, contains legitimate file path.  I'll give it a try.
Make sure you set the Reference!
The article has a working sample at the end of it.
Avatar of clock1

ASKER

As I try this and read article, notice that author states cannot get 1000 images to work.  As stated in onset, I have 20,000 images.  But continuing to work.
I am the author.
If you want to make 1000's PRINT on a report, well, yeah, that doesn't fly.
Processing 10's of thousands for length and width?  Piffle.
Avatar of clock1

ASKER

How do I earn Piffle when  I stated 20,000 images at beginning.  Sorry, no go solution.
Sigh. YOU don't earn piffle.  The task at hand does :)

Getting a thousand jpgs to print on a report is VERY difficult for Access.
Getting Access to process 20K images for which you have fully qualified paths is child's-play for Access.
It'll be resource-intensive and take a bit, but eminently doable.
About 15-20 minutes or so for 20K files

Hence, piffle.

Sample attached.
This one takes 20K records from one table, finds if they exists and adds results to a second table.
Not quite what you are doing, but I am not altering production data for a sample!  You don't have my files, but the code and tables are tested and work.
piffle.mdb
Avatar of clock1

ASKER

Opened mdb.  Clicked process. Expected to see dimension added to picture table.  What have I overlooked?
Avatar of clock1

ASKER

Disregard last comment from me.  Realize that images are on your location and no error checking in place.
The error checking is in place -- but since fs.FileExists(ThePath) will return false in every case on your machine, that's the branch that runs, and no records get written.
Replace the data in tblPictures with valid data of your own and you are in business.
Avatar of clock1

ASKER

Error checking as in MsgBox stating done appeared without error.  I'm good to try again.
Going home for the weekend!
Hopefully, the code made sense to you.

Nick67
Avatar of clock1

ASKER

Made sense.  Thanks, points are yours!
Avatar of clock1

ASKER

Made sense.  Thanks, points are yours!
You're welcome!