VBA – Manipulate Images, Resize, Convert and More …

Have you ever need to modify images through your database, or any other Office program (Excel, Word, …) for that matter?

In my last post VBA – Resize Image I demonstrated how you can do basic manipulations using the WIA object, but what about performing more advanced jobs? What about converting images between formats, … ? What about some of the headaches that occur with WIA.

Well, I set out to find a reliable solution that would work across the board and enable a vast array of manipulations and FreeImage was one such answer.

Why FreeImage you may ask, well, there are 3 main reasons (+1 personal reason):

  • It is free
  • It is relatively easy to implement and get up and running
  • Provides lots of functionalities
  • And I simply wanted to explore this option to see what it might offer to the community at large

So I have put together a simple demo to illustrate a little of what can be done and show people how to set things up.  From there, with the FreeImage documentation and simply by looking at the available functions in the FreeImage code module you should be able to add other functionalities as your needs may dictate.  For me, the demo illustrates the most common needs:

  • Resize an image by Height, Width or combination thereof
  • Rotate and image
  • Convert an image into another image format
  • Rename an image file
  • Read an image’s EXIF information
  • Determine an image’s files size

Disclaimer/Notes:

If you do not have Microsoft Access, simply download and install the freely available runtime version (this permits running MS Access databases, but not modifying their design):

Microsoft Access 2010 Runtime
Microsoft Access 2013 Runtime
Microsoft Access 2016 Runtime
Microsoft 365 Access Runtime

All code samples, download samples, links, ... on this site are provided 'AS IS'.

In no event will Devhut.net or CARDA Consultants Inc. be liable to the client/end-user or any third party for any damages, including any lost profits, lost savings or other incidental, consequential or special damages arising out of the operation of or inability to operate the software which CARDA Consultants Inc. has provided, even if CARDA Consultants Inc. has been advised of the possibility of such damages.

Also note, that this is merely a simple demo to illustrate keep concepts and functionalities. Before moving it into production, proper error handling should be added throughout, variable validation needs to be enforced and testing of the overall application needs to be performed.

Download

Feel free to download a copy (accde) by using the link provided below:

Download “FreeImage Demo (accde x32)” FreeImage_V1.04_accde.zip – Downloaded 17152 times – 2.06 MB Download “FreeImage Demo (2007 accde x32)” FreeImage_V1.04_2007x32_accde.zip – Downloaded 8427 times – 4.19 MB

Version History

V1.04 (2017-01-27)

  • Added preview image
  • Added file sizes (original and preview)
  • Added rotation functionalities
  • Code changes
  • Changed copyright info in VBA to allow reuse of all my code

V1.03 (2017-01-23)

  • Added code to warn regarding overwriting existing files since FreeImage blindly overwrite without any prompts.
  • Minor layout optimization

V1.02 (2017-01-23)

  • Added Color and BPP information about original image
  • Added ability to set the Image Format (Grey Scale, Sepia, Full Color) of the new image
  • Added option to open the file automatically once created

V1.01 (2017-01-23)

  • Added image EXIF details in listbox to demonstrate the ability to read such information
  • Fixed the form’s tab order

V1.00 (2017-01-23)

  • Initial Release

Special Thanks!

I wanted to especially thanks Tom van Stiphout, Ben Clothier, Gustav Brock, Jack Leach & Albert Kallal (with inspiration from Stephen Lebans) for helping work out how to consume a dll without needing to add it to a system folder (I did not want to get into messing with system folders, permission issues …).  As you’ll be able to see by examining the demo database, it consumes the dll that is contained in the same folder as the database itself (although the location could easily be changed).

11 responses on “VBA – Manipulate Images, Resize, Convert and More …

  1. azer

    1) I got access 64 bits , i did rename the dll as explained, then had to go in all the modules and form vba code to add the PTRSAFE in the declare function and declare sub
    still when i open the database , it tells me that the “on open” call for a function that is not compatible with 64bit.
    I don’t know if there is a procedure to do to make all the 32 bits accdb compatible by defaut to the 32b , it is so dumb from Microsoft to not do an automatation to add the ptrsafe ..

    any ideas ?

    2) there is an interesting feature that could be usefull : copy the original image to a folder so if later we decide to resize all the photos trough a function , it will reprocess all the originals .. that was something i saw in some script using imagemagik. what do you think of it ?

    1. Daniel Pineault Post author

      1) I don’t have a 64bit installation currently. I will change the download and will have to build a machine to do some testing.

      2) In the most recent version, I added a confirmation prior to saving to avoid automatic overwriting of existing files. It also wouldn’t be hard to add a simple filecopy to the process, but this become a personalization that not everyone will want, especially since you already have the ability to specify the folder where to save the processed images.
      I do want to add some other functionalities: rotation, preview, …, but am a little busy right now. I’m hoping to be able to add these some time next week.

  2. Steve Pestillo

    Hi. Can you let me know if this converter is able to set the background of images to transparent?

  3. Danny Sanders

    I work with access 2010 and get a message that i need to use a newer version of Access?

    1. Daniel Pineault Post author

      I create most of my demos now in Access 2013. I can’t make any promises, but I see if I can downgrade a copy of that demo in particular for you.

  4. Adelina

    Hi. If i purchase the full version, can i use it to store images in access table and then retreive it as picturedata? I’m already doing something like this, but with certain bmps, the function i’m using cuts the first 2-3 lines from the image…
    Thanks