简体   繁体   中英

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.

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.

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? 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.

In 2002 Microsoft released Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting .

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.

The Library is part of modern versions of Windows but can be installed into WinXP (SP1 or better).

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:

FreeImage is an open-source library; there is a download which includes a DLL that can be used by VB6.

The VB Helper link is to an article to make use of .NET from VB6 via a VB.NET DLL.

Finally, the MVPS link is VB6 code to save an image to JPG using GDI+.

Yes it can! See this excellent contribution on Planet source Code

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. Since Vista Microsoft have included WIA support within Windows.

See Microsoft's Windows Image Acquisition Automation Layer page for full details.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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