+ Reply to Thread
Results 1 to 13 of 13

Resize picture before loading it into an activex image control

  1. #1
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Question Resize picture before loading it into an activex image control

    Hi good people,

    I was experimenting with image control and different sized pictures (same picture, different dimensions) and I noticed that if the loaded picture is big (maybe 2k...or more), like a photo from a cellphone for example, the file size is just toooooo big.

    The test: on my sheet I put an image control that is small, like 168x114 pixels (and i do not need to enlarge the picture).

    It is like same sort of thumbnail, just a little bigger.

    So I opened photoshop and I reduced the dimensions of one photo (jpeg) and saved it as it was, like 2200x1415px, then 640x480px, then 240x160px.

    Aspect ratio differences are not notable.

    I loaded the 3 pictures into the image control of 3 different excel files and saved them. Visually I cannot notice any difference.

    Again, the size of the image control is the same in the 3 files.

    So I got:

    A) file with big photo (originally 120kb - 2200x1415px) = 4.4 Mb (crazy!)

    B) file with medium photo (originally 18 KB - 640x480px) = 577 KB (better)

    C) file with small Photo (originally 4.2 KB - 240x160px) = 112 KB (almost good)

    I will have lots of pictures inside several image controls so I really need to resize the photos before insertion into the image controls.

    And I cannot ask the user to do it in photoshop before inserting...

    My question is: It is possible with Excel to resize the pictures to a small dimension BEFORE loading them, via VBA, into the image controls?

    Is there some different workaround without using external software?

    Thank everybody

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Here's a nifty little function that I just tried in Excel and it seemed to work great.

    VBA – Resize Image

    Call the function like this...

    x = WIA_ResizeImage("Original path and file name", "New path and file name", MaxWidth, MaxHeight)

    The function will return True when the Resize operation is successful and False in all other cases. So you can validate your calls to the function very easily
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    Wow serious stuff! I will test it... hopefully will have no problems. Actually I was thinking in something similar... in theory!

    ............ a few hours later......

    But please elaborate a bit...

    Where do I put the code? Module1?

    Please Login or Register  to view this content.
    That is the code I am using to load the pictures...fotoAddress is the path to the picture that I carry from the insertion userform...

    How do I call it from here?

    My picture is first loaded into a userform the usual way... (see below code).

    Then the picture is "sent" to another sheet that I called RICETTEDATABASE via the code above, where it stays forever with other data like name, address etc.
    The picture in the userform is resetted after insertion... doesn't stays... so here no problems.

    Please Login or Register  to view this content.
    Thanks!
    Last edited by Alex Piotto; 03-13-2018 at 02:24 PM.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Put the function (code ) in Module1

    The function resizes the image you tell it (the full path name) and saves a new image file with a new image name that you give it.

    Something like this might work (not tested). Change the 200,400 to the max width\height of the reduced image to suit.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    Hi AlphaFrog... Time zone difference made me thank you several hour later...

    I am getting a big error from the WIA code...

    Like:

    ERROR NUMBER: 429
    ERROR SOURCE: WIA_ResizeImage
    ERROR DESCRIPTION: ActiveX component can't create object.


    I only changed the line near the end
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    and I can see the path is there, pointing to the small version of the picture... but the little picture is not there, as the error explains...

    Next move? The resize function is waaaay too advanced for me to mess with....

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Did it create a new smaller image of the selected image? Check the folder.

    Did you put the WIA_ResizeImage code in Module1 in the same workbook with the userform, and is it still named exactly WIA_ResizeImage?

    What are the old and new image names?

  7. #7
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    Yes...
    WIA_ResizeImage is in module1 - Just copied and pasted from the link you gave me

    In the folder where the picture is, there is not a smaller version of the picture.

    But in the form I can see (in a text box) the path to the photo... it is like NAMEOFPHOTO_Small.jpg The path is correct but the small photo is not there.

    The error says:" ActiveX component can't create object"... so no small pic.

    In module 1 I also have a small sub with option explicit... that put the name of the picture in the database sheet so i can retrieve it.

    How do I attach a file?
    Last edited by Alex Piotto; 03-14-2018 at 09:58 AM.

  8. #8
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    got it... here it come. In the first sheet there is a button to open the form. Try to load a photo under the logo....

    After the error is closed look down under all the buttons... the path is there.
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Are the images you are selecting on a local drive or on a networked path?

    As a test, put this in Module1 ans run it just to see if it creates a new small image file. Change the Orignal image name to an actual image on your hard drive, and add a new image name (include the full file paths).

    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Using your workbook, it works for me. Don't know what to tell you.

  11. #11
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    Images are in my local drive...

    Please Login or Register  to view this content.
    Also in module 1 obviously there is the WIA_ResizeImage.

    I get the same error message. May be is my excel 2007? I am on windows XP too....
    Last edited by Alex Piotto; 03-14-2018 at 10:37 AM.

  12. #12
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Resize picture before loading it into an activex image control

    Just tested on a friend PC with windows 7 and ecxel 2016... it works.

    Thanks anyway!

    It is time for me to change PC....

    Nice code nice support. Grazie! (thank you in italian...)

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resize picture before loading it into an activex image control

    Prego .

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] resize loaded picture to activex image object size
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2016, 03:48 AM
  2. Image picture resize and save as on differen location
    By cemregunay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2014, 06:30 AM
  3. Displaying and Updating Image Dynamically (ActiveX Image Control?)
    By VTHokie11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2011, 10:57 AM
  4. Image Position within ActiveX Image Control
    By gerryiscool in forum Excel General
    Replies: 0
    Last Post: 09-07-2011, 02:08 AM
  5. Picture loading in image problem
    By hunsnowboarder in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2008, 11:36 AM
  6. [SOLVED] Programatically control picture property of Image control
    By Brassman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2005, 05:06 PM
  7. Programatically control picture property of Image control
    By Brassman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2005, 10:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1