views:

141

answers:

2

I'm developing a script using VBScript and I need to validate the input file as a 16-Bits BMP.

At the time my script is like this:

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\16bmp.bmp" , "D:\test.bmp", OverwriteExisting

But How can I validate the input file as a 16-Bits BMP?



PS: Remember that I need this to be compatible with my site and Windows CE(I will develop a program for it using NSBasic).

+1  A: 

You would have to read the file data and compare it to the BMP format specification.

There are three ways I know of to work with binary files in VBScript:

  1. Using the ADODB component. This method is kind of limited. You can find an article about it at VBScript Read Binary File.
  2. You could write your own COM component and call it from the script. I did a quick Google search and found some ready-made components that offer this functionality.
  3. You could also install ImageMagick and use it to identify the BMP. That might be overkill for your purposes though.
Dana Holt
+1  A: 

I'm not sure I got you right (English being my second language), but if you need to check if a file is a 16-bit BMP image (and not verify the actual pixels), you can make use of the Windows Image Acquisition (WIA) scripting objects. Here's an example:

Const wiaIDUnknown = "{00000000-0000-0000-0000-000000000000}"
Const wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"

Set oImg = CreateObject("Wia.ImageFile")

On Error Resume Next

oImg.LoadFile("C:\image.bmp")

If oImg.FormatID = wiaIDUnknown Then
  ' The file isn't an image file
Else
  Log.Message "Is BMP: " & (oImg.FormatID = wiaFormatBMP)
  Log.Message "Color depth: " & oImg.PixelDepth
End If

This script requires that you have the wiaaut.dll library installed and registered on your computer; if you don't have it, you can download it as part of the WIA SDK.

See also WIA documentation on MSDN.

Helen
I got this error: `ActiveX component can't create object 'Wia.ImageFile'`, also I forgot to say that this need to be compatible with Windows CE(via NSBasic).
Nathan Campos
Most probably you don't have the wiaaut.dll library registered (see note in the end of the answer). I don't know whether Windows CE supports WIA though.
Helen