How to convert an image file to BMP programmatically using native Windows XP capabilities?
-
26-09-2019 - |
Question
Is it possible to convert an image file to BMP format using WindowsXP's native libraries and scripting capabilities?
I'm talking about WSH, JScript, VBS, etc...
C++ is also good for what I need if it can be compiled with Dev-C++
Solution
Yes, you can. Look at the Image class which is part of GDI+.
OTHER TIPS
To convert images from scripts, you can use the WIA Automation Library. It's not strictly "native" library, but it's redistributable (refer to EULA).
Blow is a JScript example that shows how to convert an image to BMP. The original image can be PNG, GIF, JPEG or TIFF. Before running the script, register the wiaaut.dll library in the system.
var wiaIDUnknown = "{00000000-0000-0000-0000-000000000000}";
var wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}";
// Load the original image
var img = new ActiveXObject("WIA.ImageFile");
img.LoadFile("D:\\MyFolder\\MyImage.gif");
switch (img.FormatID)
{
case wiaIDUnknown:
// Unknown image format or an invalid image file
break;
case wiaFormatBMP:
// The image is already BMP
break;
default:
// Specify the new format
var ip = new ActiveXObject("WIA.ImageProcess");
ip.Filters.Add(ip.FilterInfos("Convert").FilterID);
ip.Filters(1).Properties("FormatID").Value = wiaFormatBMP
// Convert and save the image
img = ip.Apply(img);
img.SaveFile("D:\\MyFolder\\MyImage.bmp");
}
See also WIA documentation on MSDN.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow