16-Bits BMP Validation
-
23-09-2019 - |
문제
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).
해결책
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.
다른 팁
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:
- Using the ADODB component. This method is kind of limited. You can find an article about it at VBScript Read Binary File.
- 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.
- You could also install ImageMagick and use it to identify the BMP. That might be overkill for your purposes though.