VBA - Image Dimensions (Width and Hieght) in Pixels, without loading into a control

Posted on 2005-05-04
Last Modified: 2008-03-06
Hi There.

I have an Image Batching application that I am writting in Access2000 (will upgrade to 2003 soon) on XP Sp1. It handles sometimes over 800 images at a time that vary from 5mb to 114mb+ in size.

For each selected file (that is stored on a CD/Removable Media/Any Drive), I need a VBA function to retrieve, and store in an existing table, the following info:

* Filename with extension - not the full path.
* Image Width in Pixels
* Image Height in Pixels

As the files are so huge, and many, I don't want to load them into a control on a form, but reference them directly from their current path. And I need to do it very quickly.

The stdOle and Access image objects cannot handle .tif files, otherwise I would be out of the woods. (ie: IPictureDisp )

I was looking at GDI+ API calls to retreive the info, but this is beyond my programming scope. I don't want to rely on purchasing ActiveX controls to handle it.

This API Function: GetBitmapDimensionEx doesn't work, because 'the retrieved dimensions must have been set by the SetBitmapDimensionEx function' (MSDN).

Windows Explorer accesses the dimensions of the bitmaps (Tiff's and Jpeg's) perfectly and super quick, and is displayed by choosing View>Details, then View>Choose Details and 'Checking' the Dimensions box. That information is all I need, but I need it in an MS Access table.

Simple Question, difficult answer.

Please Help!

Question by:SikDave
    LVL 13

    Accepted Solution

    Hi SikDave,
    For jpg, bmp, png and gifs, you can use something like this: (look at the code for imgsz.asp on the bottom) - it reads the dimensions directly out of the image file without having to load it into any control.
    For tiffs, you could extend the code using this as a guide: , check the tags 7 and 8 (ImageLength and ImageWidth).
    Using a system like that, you can read the size directly without having to load / parse the whole image into memory. It's quite a bit faster, but requires a larger chunk of code (and testing). Another possibility would be a component like "Full Image Info":
    Hope this helps :)
    LVL 48

    Expert Comment

    by:Gustav Brock
    You may be better off with a library (dll, no ActiveX) which can do bunches of other things as well like ImgSource:

    You may not even need the registrered version ...


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often nā€¦
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now