|
-
May 16th, 2026, 01:19 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] webp convert to jpg
Hi All. does anyone have any code that converts a webp image to jpg. i have used freeimage.dll ver 3.18 and MFreeImage ver 2.24 and strangely one time it works and then the next it doesn't on the same image.
i am trying to use.
Code:
dib = FreeImage_LoadEx(Source, FILO_LOAD_DEFAULT, 300, 450)
bOK = FreeImage_Save(FIF_JPEG, dib, Destination, 0)
' Unload the dib
FreeImage_Unload (dib)
or this
Code:
Public Function ConvertWebPToJPG2(webpFile As String, jpgFile As String) As Boolean
Dim dib As Long
Dim Success As Long
' Initialize FreeImage
FreeImage_Initialise True
' Load WebP image
dib = FreeImage_Load(FIF_WEBP, webpFile, 0)
If dib = 0 Then
MsgBox "Failed to load WebP image!"
FreeImage_DeInitialise
ConvertWebPToJPG2 = False
Exit Function
End If
' Save as JPG
Success = FreeImage_Save(FIF_JPEG, dib, jpgFile, 0)
' Free resources
FreeImage_Unload dib
FreeImage_DeInitialise
ConvertWebPToJPG2 = (Success <> 0)
End Function
I am downloading images from trakt and then want to convert to jpg and resize to show in a picture box.
i just need something 100% everytime.
thanks
Last edited by k_zeon; May 16th, 2026 at 01:25 AM.
-
May 16th, 2026, 03:37 AM
#2
Re: webp convert to jpg
Take a look at the "Windows Imaging Component" (WIC). WIC can read WEBP files and save them back in various image formats.
-
May 16th, 2026, 05:58 AM
#3
Thread Starter
Fanatic Member
Re: webp convert to jpg
 Originally Posted by -Franky-
Take a look at the "Windows Imaging Component" (WIC). WIC can read WEBP files and save them back in various image formats.
tks.
So i tried the below code and it wont load the image i downloaded from trakt. errors at Img.LoadFile SrcFile
Code:
Public Function ConvertWebPToJpg( _
ByVal SrcFile As String, _
ByVal DstFile As String, _
Optional ByVal Quality As Long = 90) As Boolean
On Error GoTo EH
Dim Factory As WIA.ImageFile
Dim Proc As WIA.ImageProcess
Dim Img As WIA.ImageFile
' Load WEBP
Set Img = New WIA.ImageFile
Img.LoadFile SrcFile
' Create conversion process
Set Proc = New WIA.ImageProcess
' Convert to JPEG
Proc.Filters.Add Proc.FilterInfos("Convert").FilterID
Proc.Filters(1).Properties("FormatID").Value = _
"{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" ' JPEG GUID
Proc.Filters(1).Properties("Quality").Value = Quality
' Apply conversion
Set Factory = Proc.Apply(Img)
' Save JPG
Factory.SaveFile DstFile
ConvertWebPToJpg = True
Exit Function
EH:
ConvertWebPToJpg = False
MsgBox Err.Description, vbExclamation
End Function
-
May 16th, 2026, 06:38 AM
#4
Re: webp convert to jpg
WIA is not WIC.
-
May 16th, 2026, 07:06 AM
#5
Thread Starter
Fanatic Member
Re: webp convert to jpg
 Originally Posted by -Franky-
WIA is not WIC. 
sorry my bad. will keep looking for Windows Imaging Component example. in the mean time , i found a class that does WictoPic and then added GDI+ to resize the image. so i think i may have what i need.
once its complete i should post to site.
-
May 16th, 2026, 12:14 PM
#6
Re: webp convert to jpg
[VB6] Intro to the Windows Imaging Component (WIC): Scale and convert to JPG or PNG
It will open webp and save to any of the save formats (can't save to webp) if you add it to the common dialog filter. Not strictly required but should add a codec entry in OpenFile:
Code:
If IsEqualIID(tCF, GUID_ContainerFormatWebp) Then mCodec = WFF_WEBP
and a value in the WFF_ enum... it's just arbitrary for the class, not an api const.
It might need an additional codec from the store (not specific to my demo, any WIC solution might) depending on Windows version. The save to jpg option supports setting the quality %.
The twinBASIC version added webp to the filter list and added save to bmp too. And x64 support of course.
edit: scaled and saved, def works
Last edited by fafalone; May 16th, 2026 at 02:27 PM.
-
May 19th, 2026, 02:11 PM
#7
Thread Starter
Fanatic Member
Re: webp convert to jpg
I have created a little app to show loading a webp image to a picturebox and also how to resize the webP and convert to Jpg at the same time.
The Wic class was not created by me and is on the forum somewhere.
The GDI resize code was.

Resize and convert WebP to Jpg.zip
-
May 19th, 2026, 07:05 PM
#8
Re: [RESOLVED] webp convert to jpg
For what it's worth here's the shortest possible equivalent function that converts any image file (including webp) to JPG with optional resizing. No Wic, no GdiPlus required:
Code:
Private Sub ConvertToJpg(sSourceFile As String, sJpgFile As String, Optional ByVal NewWidth As Long, Optional ByVal NewHeight As Long)
Dim StorageFile As IStorageFile, DecoderStream As IRandomAccessStream, EncoderStream As IRandomAccessStream, BitmapEncoder As IBitmapEncoder, JpegEncoderId As UUID, _
BitmapEncoderWithSoftwareBitmap As IBitmapEncoderWithSoftwareBitmap, BitmapFrameWithSoftwareBitmap As IBitmapFrameWithSoftwareBitmap, SoftwareBitmap As ISoftwareBitmap
With New cAwait
If .Await(StorageFileStatics.GetFileFromPathAsync(StrRef(sSourceFile))) = AsyncStatus_Completed Then
Set StorageFile = .GetResults
If .Await(StorageFile.OpenAsync(FileAccessMode_Read)) = AsyncStatus_Completed Then
Set DecoderStream = .GetResults
If .Await(BitmapDecoderStatics.CreateAsync(DecoderStream)) = AsyncStatus_Completed Then
Set BitmapFrameWithSoftwareBitmap = .GetResults
If .Await(BitmapFrameWithSoftwareBitmap.GetSoftwareBitmapAsync) = AsyncStatus_Completed Then
Set SoftwareBitmap = .GetResults
If .Await(FileRandomAccessStreamStatics.OpenWithOptionsAsync(StrRef(sJpgFile), FileAccessMode_Write, StorageOpenOptions_None, FileOpenDisposition_CreateAlways)) = AsyncStatus_Completed Then
Set EncoderStream = .GetResults: JpegEncoderId = BitmapEncoderStatics.JpegEncoderId
If .Await(BitmapEncoderStatics.CreateAsync(JpegEncoderId.Data1, JpegEncoderId.Data2, JpegEncoderId.Data3, JpegEncoderId.Data4, EncoderStream)) = AsyncStatus_Completed Then
Set BitmapEncoder = .GetResults: Set BitmapEncoderWithSoftwareBitmap = BitmapEncoder: BitmapEncoderWithSoftwareBitmap.SetSoftwareBitmap SoftwareBitmap
If NewWidth > 0 And NewHeight > 0 Then
With BitmapEncoder.BitmapTransform: .ScaledWidth = NewWidth: .ScaledHeight = NewHeight: .InterpolationMode = BitmapInterpolationMode_Fant: End With
End If
If .Await(BitmapEncoder.FlushAsync) = AsyncStatus_Completed Then Dispose EncoderStream: Dispose DecoderStream: Dispose SoftwareBitmap
End If
End If
End If
End If
End If
End If
End With
End Sub
Typical usage:
Code:
ConvertToJpg App.Path & "\FileName.webp", App.Path & "\FileName.jpg"
Requires the WinRT TypeLib and helper modules.
-
May 19th, 2026, 11:54 PM
#9
Re: [RESOLVED] webp convert to jpg
RT is nice and definitely something good to learn and use.
WIC works for windows 7 as well, so the pick if windows 7 is what u also require.
if u need for windows 7, u need to include the webp codec as its not part of the OS.
-
May 20th, 2026, 12:10 AM
#10
Re: [RESOLVED] webp convert to jpg
I believe that WinRT uses WIC in the background for image files, and Media Foundation for audio and video files. The difference is that, in WinRT, the code is somewhat shorter and simpler compared to writing the same functionality using WIC or Media Foundation directly.
-
May 20th, 2026, 01:00 AM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] webp convert to jpg
 Originally Posted by VanGoghGaming
For what it's worth here's the shortest possible equivalent function that converts any image file (including webp) to JPG with optional resizing. No Wic, no GdiPlus required:
Code:
Private Sub ConvertToJpg(sSourceFile As String, sJpgFile As String, Optional ByVal NewWidth As Long, Optional ByVal NewHeight As Long)
Dim StorageFile As IStorageFile, DecoderStream As IRandomAccessStream, EncoderStream As IRandomAccessStream, BitmapEncoder As IBitmapEncoder, JpegEncoderId As UUID, _
BitmapEncoderWithSoftwareBitmap As IBitmapEncoderWithSoftwareBitmap, BitmapFrameWithSoftwareBitmap As IBitmapFrameWithSoftwareBitmap, SoftwareBitmap As ISoftwareBitmap
With New cAwait
If .Await(StorageFileStatics.GetFileFromPathAsync(StrRef(sSourceFile))) = AsyncStatus_Completed Then
Set StorageFile = .GetResults
If .Await(StorageFile.OpenAsync(FileAccessMode_Read)) = AsyncStatus_Completed Then
Set DecoderStream = .GetResults
If .Await(BitmapDecoderStatics.CreateAsync(DecoderStream)) = AsyncStatus_Completed Then
Set BitmapFrameWithSoftwareBitmap = .GetResults
If .Await(BitmapFrameWithSoftwareBitmap.GetSoftwareBitmapAsync) = AsyncStatus_Completed Then
Set SoftwareBitmap = .GetResults
If .Await(FileRandomAccessStreamStatics.OpenWithOptionsAsync(StrRef(sJpgFile), FileAccessMode_Write, StorageOpenOptions_None, FileOpenDisposition_CreateAlways)) = AsyncStatus_Completed Then
Set EncoderStream = .GetResults: JpegEncoderId = BitmapEncoderStatics.JpegEncoderId
If .Await(BitmapEncoderStatics.CreateAsync(JpegEncoderId.Data1, JpegEncoderId.Data2, JpegEncoderId.Data3, JpegEncoderId.Data4, EncoderStream)) = AsyncStatus_Completed Then
Set BitmapEncoder = .GetResults: Set BitmapEncoderWithSoftwareBitmap = BitmapEncoder: BitmapEncoderWithSoftwareBitmap.SetSoftwareBitmap SoftwareBitmap
If NewWidth > 0 And NewHeight > 0 Then
With BitmapEncoder.BitmapTransform: .ScaledWidth = NewWidth: .ScaledHeight = NewHeight: .InterpolationMode = BitmapInterpolationMode_Fant: End With
End If
If .Await(BitmapEncoder.FlushAsync) = AsyncStatus_Completed Then Dispose EncoderStream: Dispose DecoderStream: Dispose SoftwareBitmap
End If
End If
End If
End If
End If
End If
End With
End Sub
Typical usage:
Code:
ConvertToJpg App.Path & "\FileName.webp", App.Path & "\FileName.jpg"
Requires the WinRT TypeLib and helper modules.
just tried your code but stops on first line with error. are there any references i need to add etc ie IStorageFile not defined
-
May 20th, 2026, 04:12 AM
#12
Re: [RESOLVED] webp convert to jpg
 Originally Posted by k_zeon
just tried your code but stops on first line with error. are there any references i need to add etc ie IStorageFile not defined
You need the "WinRT Interfaces x86.tlb" file from "WinRT Interfaces x86.zip". Copy it to the "C:\Windows\SysWOW64" folder and set a reference to this TLB. You also need several files from "WinRT Samples Collection.zip" (specifically from the "WinRT Samples Collection\Common" subdirectory) that you must add to your project (mdlHelpers.bas, mdlStatics.bas, and cAwait.cls). See the link from VanGoghGaming.
-
May 20th, 2026, 07:15 AM
#13
Re: [RESOLVED] webp convert to jpg
Thanks for the detailed instructions Franky, you rock!
-
May 20th, 2026, 03:40 PM
#14
Re: [RESOLVED] webp convert to jpg
If you want a minimal implementation using WIC directly without the WinRT layer on top, this uses oleexp.tlb in VB6 or WinDevLib in twinBASIC:
Code:
Private Sub ConvertToJpg(sSourceFile As String, sJpgFile As String, Optional ByVal NewWidth As Long, Optional ByVal NewHeight As Long)
Dim pFact As WICImagingFactory, pFrame As IWICBitmapFrameDecode, pConverter As IWICFormatConverter, pScaler As IWICBitmapScaler
Dim mSave As IWICBitmapSource, pDecoder As IWICBitmapDecoder, GUIDNULL As UUID
#If TWINBASIC = 0 Then
Const vbNullPtr As LongPtr = 0
#End If
Set pFact = New WICImagingFactory
If (pFact Is Nothing) = False Then
Set pDecoder = pFact.CreateDecoderFromFilename(StrPtr(sSourceFile), GUIDNULL, &H80000000, WICDecodeMetadataCacheOnDemand)
If (pDecoder Is Nothing) = False Then
Set pFrame = pDecoder.GetFrame(0)
If NewWidth > 0 And NewHeight > 0 Then
pFact.CreateBitmapScaler pScaler
pScaler.Initialize pFrame, NewWidth, NewHeight, WICBitmapInterpolationModeHighQualityCubic
Set mSave = pScaler
Else
Set mSave = pFrame
End If
Set pConverter = pFact.CreateFormatConverter()
pConverter.Initialize mSave, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, Nothing, 0, WICBitmapPaletteTypeCustom
Dim pStream As IWICStream, pEncoder As IWICBitmapEncoder, pFrameEnc As IWICBitmapFrameEncode
pFact.CreateStream pStream
pStream.InitializeFromFilename StrPtr(sJpgFile), &H40000000
Set pEncoder = pFact.CreateEncoder(GUID_ContainerFormatJpeg, GUIDNULL)
pEncoder.Initialize pStream, WICBitmapEncoderNoCache
Dim pPropBag As IPropertyBag2
pEncoder.CreateNewFrame pFrameEnc, pPropBag
pFrameEnc.Initialize pPropBag
Dim w As Long, h As Long
pConverter.GetSize w, h
pFrameEnc.SetSize w, h
pFrameEnc.SetPixelFormat GUID_WICPixelFormat24bppBGR
pFrameEnc.WriteSource pConverter, ByVal vbNullPtr
pFrameEnc.Commit
pEncoder.Commit
End If
End If
End Sub
Then in VB6 for the GUIDs the oleexp included addons mIID.bas/mWIC.bas or just this:
Code:
Public Function GUID_WICPixelFormat24bppBGR() As UUID
Static iid As UUID
If (iid.Data1 = 0&) Then Call DEFINE_UUID(iid, &H6FDDC324, &H4E03, &H4BFE, &HB1, &H85, &H3D, &H77, &H76, &H8D, &HC9, &HC)
GUID_WICPixelFormat24bppBGR = iid
End Function
Public Function GUID_ContainerFormatJpeg() As UUID
Static iid As UUID
If (iid.Data1 = 0&) Then Call DEFINE_UUID(iid, &H19E4A5AA, &H5662, &H4FC5, &HA0, &HC0, &H17, &H58, &H2, &H8E, &H10, &H57)
GUID_ContainerFormatJpeg = iid
End Function
Private Sub DEFINE_UUID(Name As UUID, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte)
With Name
.Data1 = L: .Data2 = w1: .Data3 = w2
.Data4(0) = B0: .Data4(1) = b1: .Data4(2) = b2: .Data4(3) = B3: .Data4(4) = b4: .Data4(5) = b5: .Data4(6) = b6: .Data4(7) = b7
End With
End Sub
WinRT uses WIC under the hood so this has all the same format support, without higher version requirements that WinRT imposes.
Last edited by fafalone; May 20th, 2026 at 03:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|