如何使用本机 Windows XP 功能以编程方式将图像文件转换为 BMP?

发布于 2024-09-17 12:33:47 字数 121 浏览 11 评论 0原文

是否可以使用 WindowsXP 的本机库和脚本功能将图像文件转换为 BMP 格式?

我说的是 WSH、JScript、VBS 等...
如果 C++ 可以用 Dev-C++ 编译的话,它也能满足我的需要

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++

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

短暂陪伴 2024-09-24 12:33:47

是的,你可以。查看 Image 类,它是GDI+ 的。

Yes, you can. Look at the Image class which is part of GDI+.

酒绊 2024-09-24 12:33:47

要从脚本转换图像,您可以使用 WIA 自动化库。它不是严格意义上的“本机”库,但它是可重新分发的(请参阅 EULA)。

Blow 是一个 JScript 示例,演示如何将图像转换为 BMP。原始图像可以是 PNG、GIF、JPEG 或 TIFF。在运行脚本之前,请在系统中注册wiaut.dll库。

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");
}

另请参阅 MSDN 上的 WIA 文档

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.

夜空下最亮的亮点 2024-09-24 12:33:47

我认为从 Windows 7 开始,Windows 就提供了 WIA DLL。
否则,您可以下载WIA

这是转换为vbscript的@Helen代码:

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

Sub die(msg)
    WScript.Echo(msg)
    WScript.Quit(1)
End Sub

'-----------------------------------------------------------------
' MAIN

Set args = WScript.Arguments
If args.Count <> 2 Then die "Usage: WIA_convert.vbs <filename_input> <filename_output>"

filename_in = args.Item(0)
filename_out    = args.Item(1)

Set img_in = CreateObject("WIA.ImageFile")
img_in.LoadFile filename_in
Wscript.Echo "Width  = " & img_in.Width
Wscript.Echo "Height = " & img_in.Height

Select Case img_in.FormatID
Case wiaIDUnknown
    Wscript.Echo "Unknown format"

Case wiaFormatBMP
    Wscript.Echo "Image is BMP"

Case Else
    Set ip  = CreateObject("WIA.ImageProcess")
    ip.Filters.Add(ip.FilterInfos("Convert").FilterID)
    ip.Filters(1).Properties("FormatID").Value = wiaFormatBMP

    Set img_out = ip.Apply(img_in)
    img_out.SaveFile(filename_out)
End Select

I think from Windows 7 WIA DLL are provided with Windows.
Otherwise you can download WIA

This is @Helen code converted to vbscript:

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

Sub die(msg)
    WScript.Echo(msg)
    WScript.Quit(1)
End Sub

'-----------------------------------------------------------------
' MAIN

Set args = WScript.Arguments
If args.Count <> 2 Then die "Usage: WIA_convert.vbs <filename_input> <filename_output>"

filename_in = args.Item(0)
filename_out    = args.Item(1)

Set img_in = CreateObject("WIA.ImageFile")
img_in.LoadFile filename_in
Wscript.Echo "Width  = " & img_in.Width
Wscript.Echo "Height = " & img_in.Height

Select Case img_in.FormatID
Case wiaIDUnknown
    Wscript.Echo "Unknown format"

Case wiaFormatBMP
    Wscript.Echo "Image is BMP"

Case Else
    Set ip  = CreateObject("WIA.ImageProcess")
    ip.Filters.Add(ip.FilterInfos("Convert").FilterID)
    ip.Filters(1).Properties("FormatID").Value = wiaFormatBMP

    Set img_out = ip.Apply(img_in)
    img_out.SaveFile(filename_out)
End Select
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文