• Saving a selected graphic as BitMap /BMP

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Saving a selected graphic as BitMap /BMP

    Author
    Topic
    #363429

    How can I save a selected graphic, preferably as a Windows Bitmap?

    Either it’s darn near impossible, or my mind is going through one of its lengthier periodic brownouts.

    I have a set of GIF and JPeg etc files. I’d like to process them all, programmatically, and somehow convert them to BitMap form. Setting their image attributes would be nice, but not essential.

    In Word97/VBA as an example, I can write code that will Insert, Picture, From file and then Select the graphic.

    I can’t see a way to save the graphic in BMP format.

    I’ve looked within PPT in VBA, but have very little experience there.

    I’ve even fired up Microsoft Photo Editor and Corel Photo House, but there’s no macro/program capability there, as far as I can see.

    I don’t care if the solution involves a DOS BATch file.

    I should add that I’m reasonably comfortable with working with Clipboard objects ….

    Ideally I’d like to point some procedure (VBA/DOS etc) at a directory and have it process each file in that directory. Each file would pop up on the screen in front of me (as in Word, Insert, Picture, FromFile) and I would choose to save it or ignore it. Ignore is to go on to the next file, Save is to somehow save the image as a Windows BitMap.

    I’m wondering now whether there might not be a solution if I saved it in RTF format, but that seems to me to be clutching at straws.

    Viewing 2 reply threads
    Author
    Replies
    • #554627

      Chris

      OK since no one has answered you yet, I will take a stab at it.

      <<>>

      I guess this is due to the fact that the picture inserted is now in MS-Word, its an object of the document I think, not a stand alone file.

      <<>>

      True and this is where you need to look, since Photo Editor can save graphical files vs Word saving documents, and Excel saving spreadsheets. But again you hit the wall where once you are in the ‘shelled-to’ aplication, VBA or any other automation macro can’t control.

      So how about a 3rd party automation control macro thingy. Check http://”%5Dhttp://www.dynawares.com/macro/>http:// http://www.dynawares.com/macro/[/url] for MacroAnyWhere. So you can launch Photo Editor via VBA and then control Photo Editor via MacroAnyWhere. Possibly it would work and it maybe too much work that you may get frustrated hairout enough to save each image separatly, in which case you are done grin and don’t need a macro any more.

      Hope this helps… I don’t know I never tried such approch, but maybe you will tell us.

      Wassim

      • #554681

        > for MacroAnyWhere.

        Thanks for this. I am d/l as we squeak and will report back.

      • #554946

        I looked into this once. I think your best chance is to use a 3rd-party graphics COM DLL, I know Lead Tools is popular (http://www.leadtools.com), there are probably lots of others, maybe even some free ones!

        Peter

    • #554648

      Why save them as bmp files ?. The quality is unlikely to improve and all you achieve is to increase the file size !.

      Andrew C

    • #555149

      You can do this using an Image control and the LoadPicture and SavePicture statements.

      I put together this quick and dirty.

      Add a Userform with an Image control and a CommandButton.

      Then:

      Private Sub CommandButton1_Click()
      Dim myfile As String
      Dim mybmpfile As String
      Dim i As Integer

      Const pic_dir As String = “C:Documents and SettingsAdministratorMy DocumentsMy PicturesTest”
      Const bmp_dir As String = “C:Documents and SettingsAdministratorMy DocumentsMy PicturesBMPS”

      myfile = Dir(pic_dir & “*.*”)

      While myfile “”
      i = InStr(1, myfile, “.”)
      mybmpfile = Left(myfile, i – 1)
      myfile = pic_dir & myfile
      Image1.Picture = LoadPicture(myfile)
      SavePicture Image1.Picture, bmp_dir & mybmpfile & “.bmp”
      myfile = Dir()
      Wend

      End Sub

      The test directory contains a few jpg, gif and bmp files.

      Hope this gives you a starting point. Note that I assumed that the file name contains only one period (.).

      Regards,

      Kevin Bell

      • #555181

        > Image control

        Thank you! This is just the start I needed, and your code ran flawlessly the first time.

        • #555185

          You are more than welcome Chris. Can you tell my boss that the code ran first time? It’ll give him the heart attack he deserves. LOL

          Regards,

          Kevin Bell

          • #555249

            Sure. Pass on his email or telephone and I’ll do it. You can get my email address from my web site.

            Code that runs right first time is a good goal. If nothing else it moves us towards (1) small chunks of code (the less moving parts there are, the less parts there are to go wrong) and (2) libraries of reusable code.

      • #555349

        Late this afternoon, your few lines of code mutated into a little application that allows you to nominate a source path and a target path, and then rips through ALL files in the source path and all subdirectories creating bitmaps from each available file.

        Non-image files are skipped.

        Bitmaps are numbered with four digits corresponding to minutes and seconds, e.g. 0000, 0001, 0002, … 0059, 0100, 0101, … 0159, 0200 up to 5959, at which time the hours kick in 10000,10001,10002 etc.

        You can nominate your CD drive as the source if you want to rip every available image off a CD. Or a colelction of CDs that are lying around and who-knows-what-they-contain, right?

        In an earlier post I showed my Wallpaper.bat file. That copies a bitmap file over Daily.bmp, which is assigned as the desktop wallpaper. Wallpaper.bat uses the minutes and seconds of the system clock to identify a bitmap soiurce file.

        So, with a shortcut to Wallpaper.bat on my desktop, I can reset the desktop wallpaper anytime i want. My boot sequence invokes Wallpaper.bat, so a re-boot gives me a different wallpaper.

        I modified the wallpaper.bat to create (by Echo) a small batch file that would DELETE the current ly assigned wallpaper file, so if I get a wallpaper I don’t want anymore, I just double-click on the erase-wallpaper icon, and that file (e.g. 1347.bmp) is gone for good.

        Leaving a hole in the sequence.

        But not to worry. As the little appliaction is creating new bitmap files, it fills in any holes in the sequence before adding to the end.

        Anyay, thanks again.

        I’m a happy camper.

        • #555393

          As an aside to this thread but a related topic. Does anybody know how to invoke the built-in Graphics Converters in Office from VB or VBA?

          Just my devious mind I suppose, I’m thinking of how to go the other way, from .BMP to other graphics formats without resorting to third party software. I know there is a lot of freeware out there that’ll probably do the trick but Enquiring Minds Just Have To Know.

          Regards,

          Kevin Bell

    Viewing 2 reply threads
    Reply To: Saving a selected graphic as BitMap /BMP

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: