locked
Saving a modified Userform picture RRS feed

  • Question

  • I've been trying to write a macro in Excel to allow me to modify a picture's grayscale values.  To do this, I loaded a picture into a Userform.  I then use the API function SetPixel to modify the image.  This works fine.  I can see that my image is properly modified.  My problem is that when I use the following line to save the picture, it saves the original picture, but not the modified version.  Does anyone know how to save or copy a modified userform picture?

    SavePicture UserForm1.Picture, Filename

    Thanks.

    Wednesday, May 13, 2015 10:09 AM

All replies

  • I probably don't understand what you are doing but SetPixel just modifies the screen image not the underlying picture.  You would need to screen capture the image and save it.   I have used a tool called mincap (free) to capture screen images from VBA.  It has a command line interface you can call with VBA.  Another option is to use another tool like ImageMajick (free) to modify the image and save it directly.  It has an option to install a COM interface and you can call it directly in VBA or use the command line interface with VBA.  I would use ImageMajick.  It is very powerful and feature rich but does a bit of reading/experimenting to get what you want.  It has a very helpful user forum.

    http://www.softpedia.com/get/Multimedia/Graphic/Graphic-Capture/MiniCap.shtml

    http://www.imagemagick.org/script/index.php

    Wednesday, May 13, 2015 4:45 PM
  • Thanks for the thoughts.  Unfortunately, add-ins like these are difficult since other people will be using the same macro on their own machines.  I'll have to find something else.
    Thursday, May 14, 2015 9:06 AM
  • I include them with the installer for the addin.  I use the Inno installer.  I include all the support utilities and documentation.  I know of no capability on a normal Win7 install that will allow you to change pixels on an image.  If you are in a network environment you could create a network service/server to do this using ImageMajick.  The VBA could write the image to the service/server and poll for the result.  I have done this for certain items that required a lot of computer power.
    Thursday, May 14, 2015 11:44 AM