简体   繁体   English

VB6可以将图像另存为JPEG吗?

[英]Can VB6 save an image as a JPEG?

Note: I am NOT a VB6 programmer - I'm an Android programmer responsible for an app used in manufacturing and I have a colleague responsible for a VB6 program that talks to my Android devices. 注意:我不是VB6程序员-我是负责生产中使用的应用程序的Android程序员,并且我的同事负责与我的Android设备对话的VB6程序。

In the past our VB6 program sent Microsoft .bmps to the Android device, but now that we're adding tablets to our product list, and want to send bigger images to take advantage of the tablet's extra real-estate we find that .bmp's are too big and clog up the network. 过去,我们的VB6程序将Microsoft .bmps发送到Android设备,但是现在我们要将平板电脑添加到我们的产品列表中,并且想要发送更大的图像以利用平板电脑的额外房地产,我们发现.bmp是太大而阻塞了网络。

Eventually we're replacing the old VB6 product with a .Net one, but until we do is there any way for VB6 to programmatically convert a bitmap to a JPEG? 最终,我们用.Net替代了旧的VB6产品,但是直到我们这样做之前,VB6还是无法通过编程将位图转换为JPEG吗? My colleague is unaware of one but I've always found SO to be very useful in my domains (Android, .Net) so I thought I'd try a VB6 question here. 我的同事没有意识到这一点,但我一直发现SO在我的域(Android,.Net)中非常有用,所以我想在这里尝试VB6问题。

In 2002 Microsoft released Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting . 2002年,Microsoft发布了Windows®图像采集自动化库v2.0工具:用于VB和脚本的图像采集和处理组件

This can accept a .BMP or even a raw Windows 24-bit pixel bitmap (plus width & height) from a file or Byte array and convert them to JPEG, producing a file or Byte array result. 这可以接受来自文件或字节数组的.BMP甚至是Windows 24位原始像素位图(加上宽度和高度),并将它们转换为JPEG,从而产生文件或字节数组的结果。

The Library is part of modern versions of Windows but can be installed into WinXP (SP1 or better). 该库是Windows现代版本的一部分,但可以安装到WinXP(SP1或更高版本)中。

Simple file-to-file example: 简单的文件到文件示例:

Dim ImgF As WIA.ImageFile
Dim ImgP As WIA.ImageProcess

Set ImgF = New WIA.ImageFile
ImgF.LoadFile "Zapotec.bmp"
Set ImgP = New WIA.ImageProcess
With ImgP
    .Filters.Add .FilterInfos!Convert.FilterID
    .Filters.Item(1).Properties!FormatID.Value = wiaFormatJPEG
    .Filters.Item(1).Properties!Quality.Value = 70
    Set ImgF = .Apply(ImgF)
End With
ImgF.SaveFile "Zapotec.jpg"

MarkJ's links above are worth a look, but here are three other ideas to consider: 上面的MarkJ链接值得一看,但是这里还有另外三个要考虑的想法:

FreeImage is an open-source library; FreeImage是一个开源库; there is a download which includes a DLL that can be used by VB6. 有一个下载文件,其中包含可以由VB6使用的DLL。

The VB Helper link is to an article to make use of .NET from VB6 via a VB.NET DLL. VB帮助程序链接指向通过VB.NET DLL通过VB6使用.NET的文章。

Finally, the MVPS link is VB6 code to save an image to JPG using GDI+. 最后,MVPS链接是VB6代码,可使用GDI +将图像保存为JPG。

Yes it can! 是的,它可以! See this excellent contribution on Planet source Code 在Planet源代码中查看此杰出贡献

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=50065&lngWId=1 http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=50065&lngWId=1

Bob77's excellent answer put me on the right track, but the download link is no longer available. Bob77的出色回答使我步入正轨,但是下载链接不再可用。 Since Vista Microsoft have included WIA support within Windows. 从Vista开始,Microsoft已在Windows中包含WIA支持。

See Microsoft's Windows Image Acquisition Automation Layer page for full details. 有关完整的详细信息,请参见Microsoft的Windows图像采集自动化层页面

I found that the initial part of the code snippet needed to be tweaked to refer to the bundled WIA class, which is now called WIACtl. 我发现需要对代码片段的初始部分进行调整,以引用捆绑的WIA类,该类现在称为WIACtl。

Dim ImgF As WIACtl.ImageFile
Dim ImgP As WIACtl.ImageProcess

Set ImgF = New WIACtl.ImageFile
ImgF.LoadFile "Zapotec.bmp"
Set ImgP = New WIACtl.ImageProcess

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM