Results 1 to 18 of 18

Thread: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Classes

  1. #1

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Thumbs up VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Classes

    UPDATE: post #16 below contains a new version of this project using a XAML Image Control instead of a vanilla PictureBox!

    This project allows you to convert various picture formats, optionally apply some transforms (Scale, Flip, Rotation, Crop) and save the result as another format.

    A TypeLib with the required WinRT interface definitions is included in the ZIP archive, don't forget to set a reference to it.

    Many picture formats are supported as seen in this screenshot. Transparency is preserved for PNGs, GIFs and other formats supporting it.

    Name:  BitmapEncoder.jpg
Views: 1917
Size:  57.5 KB

    Here is the demo project: BitmapEncoder.zip

    Requirements: Windows 10 or later!

  2. #2
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    632

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    very good job VanGoghGaming

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    On my Win11 machine it lists a .webp decoder only (no encoder) which is weird.

    Do I need to pay something to get and encoder from MS Store or something?

    cheers,
    </wqw>

  4. #4

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    I think Microsoft only included a WebP decoder. There might have been some copyright issues and they didn't want to pay royalties to Google to include an encoder as well...

  5. #5
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    I've been using MS Office graphic filters to support most fringe image formats but your work looks promising and will probably implement these as fallback loading routines (sequenced just before shelling IrfanView with /silent /clipcopy /cmdexit parameters as last resort:-))

    cheers,
    </wqw>

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    As I understand it the WinRT bitmap classes are using WIC under the hood; format support here exactly matches what it has, if you don't want the extra layer and Win10 requirements on top

  7. #7

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    That's like saying everything uses assembly under the hood so why not use that instead!

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    If that's your argument, you realize using WinRT in VB is complicating it to a very similar degree over using it in .NET

    Even that's stretching it; using WIC directly isn't much more complicated at all.
    Last edited by fafalone; May 2nd, 2025 at 02:46 PM.

  9. #9

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    In my experience this hasn't been the case at all. Using "DispCallFunc" to do everything manually was indeed complicated but those days are long gone. Now, using WinRT from a native language like VB/tB is very similar to using it in .NET but without the overhead due to bloated runtime dependencies. So it's the best of both worlds.

  10. #10
    Hyperactive Member
    Join Date
    Feb 2015
    Posts
    324

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    Very nice! I wrote a similar application about 15 years ago using GDI+ for rendering & a few other things along with FreeImage for formats unsupported by GDI+.

  11. #11

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Lightbulb Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    For anyone interested in saving HEIF images I am linking here Franky's instructions on how to get the HEVCVideoExtension codec from the Microsoft Store for free (otherwise it costs $0.99). Confirmed it works!

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    > Even that's stretching it; using WIC directly isn't much more complicated at all.

    WIC even allows using it without a typelib but with "proxy" API declares like Private Declare Function WICCreateImagingFactory_Proxy Lib "windowscodecs" (ByVal SDKVersion As Long, ppIImagingFactory As stdole.IUnknown) As Long and I just realized I already have a working WicLoadPicture implementation using these proxy functions.

    On second thought it might be good idea to clean it up in a separate module, add AllowAlpha parameter and bundle it with WicSavePicture and WicSavePictureToArray for a general purpose replacement of built-in functions as a CodeBank submission. WIC is XP compatible but even better on Win10+ it supports HEIF/WEBP and all modern image file format which is an attractive proposal for compatibility targets of LOBs in VB6.

    cheers,
    </wqw>

  13. #13
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    FYI all WIC proxy APIs are declared in WinDevLib too. I've really gotten into the whole 'no more copying/pasting/porting APIs individually' thing.

    Code:
    Public Declare PtrSafe Function WICCreateColorTransform_Proxy Lib "windowscodecsext.dll" (ppIColorTransform As Any) As Long
    Public Declare PtrSafe Function IWICColorTransform_Initialize_Proxy Lib "windowscodecsext.dll" (ByVal pIColorTransform As stdole.IUnknown, ByVal pIBitmapSource As stdole.IUnknown, ByVal pIContextSource As stdole.IUnknown, ByVal pIContextDest As stdole.IUnknown, pixelFmtDest As UUID) As Long
    Public Declare PtrSafe Function WICCreateColorContext_Proxy Lib "windowscodecs.dll" (ByVal pImagingFactory As stdole.IUnknown, ppIWICColorContext As stdole.IUnknown) As Long
    Public Declare PtrSafe Function WICCreateImagingFactory_Proxy Lib "windowscodecs.dll" (ByVal SDKVersion As Long, ppIImagingFactory As stdole.IUnknown) As Long
    Public Declare PtrSafe Function WICSetEncoderFormat_Proxy Lib "Windowscodecs.dll" (ByVal pSourceIn As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown, ByVal pIFrameEncode As stdole.IUnknown, ppSourceOut As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IEnumString_Next_WIC_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal celt As Long, rgelt As LongPtr, pceltFetched As Long) As Long
    Public Declare PtrSafe Function IEnumString_Reset_WIC_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IPropertyBag2_Write_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cProperties As Long, pPropBag As PROPBAG2, ByVal pvarValue As LongPtr) As Long
    Public Declare PtrSafe Function IWICBitmapClipper_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pISource As stdole.IUnknown, prc As WICRect) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_DoesSupportAnimation_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pfSupportAnimation As BOOL) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_DoesSupportLossless_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pfSupportLossless As BOOL) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_DoesSupportMultiframe_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pfSupportMultiframe As BOOL) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_GetContainerFormat_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pguidContainerFormat As UUID) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_GetDeviceManufacturer_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchDeviceManufacturer As Long, ByVal wzDeviceManufacturer As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_GetDeviceModels_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchDeviceModels As Long, ByVal wzDeviceModels As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_GetFileExtensions_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchFileExtensions As Long, ByVal wzFileExtensions As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICBitmapCodecInfo_GetMimeTypes_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchMimeTypes As Long, ByVal wzMimeTypes As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_CopyPalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetColorContexts_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cCount As Long, ByRef ppIColorContexts As stdole.IUnknown, ByRef pcActualCount As Long) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetDecoderInfo_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIDecoderInfo As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetFrameCount_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pCount As Long) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetFrame_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal index As Long, ppIBitmapFrame As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetMetadataQueryReader_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIMetadataQueryReader As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetPreview_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIBitmapSource As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapDecoder_GetThumbnail_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIThumbnail As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_Commit_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_CreateNewFrame_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIFrameEncode As stdole.IUnknown, ByRef ppIEncoderOptions As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_GetEncoderInfo_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIEncoderInfo As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_GetMetadataQueryWriter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIMetadataQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIStream As stdole.IUnknown, ByVal cacheOption As WICBitmapEncoderCacheOption) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_SetPalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapEncoder_SetThumbnail_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIThumbnail As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFlipRotator_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pISource As stdole.IUnknown, ByVal Options As WICBitmapTransformOptions) As Long
    Public Declare PtrSafe Function IWICBitmapFrameDecode_GetColorContexts_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cCount As Long, ByRef ppIColorContexts As stdole.IUnknown, ByRef pcActualCount As Long) As Long
    Public Declare PtrSafe Function IWICBitmapFrameDecode_GetMetadataQueryReader_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIMetadataQueryReader As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameDecode_GetThumbnail_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIThumbnail As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_Commit_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_GetMetadataQueryWriter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIMetadataQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIEncoderOptions As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_SetColorContexts_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cCount As Long, ByRef ppIColorContext As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_SetResolution_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal DpiX As Double, ByVal DpiY As Double) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_SetSize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal uiWidth As Long, ByVal uiHeight As Long) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_SetThumbnail_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIThumbnail As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapFrameEncode_WriteSource_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIBitmapSource As stdole.IUnknown, prc As WICRect) As Long
    Public Declare PtrSafe Function IWICBitmapLock_GetStride_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pcbStride As Long) As Long
    Public Declare PtrSafe Function IWICBitmapLock_GetDataPointer_STA_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pcbBufferSize As Long, ByRef ppbData As LongPtr) As Long
    Public Declare PtrSafe Function IWICBitmapScaler_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pISource As stdole.IUnknown, ByVal uiWidth As Long, ByVal uiHeight As Long, ByVal mode As WICBitmapInterpolationMode) As Long
    Public Declare PtrSafe Function IWICBitmapSource_GetSize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef puiWidth As Long, ByRef puiHeight As Long) As Long
    Public Declare PtrSafe Function IWICBitmapSource_GetPixelFormat_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pPixelFormat As UUID) As Long
    Public Declare PtrSafe Function IWICBitmapSource_GetResolution_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pDpiX As Double, ByRef pDpiY As Double) As Long
    Public Declare PtrSafe Function IWICBitmapSource_CopyPalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmapSource_CopyPixels_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, prc As WICRect, ByVal cbStride As Long, ByVal cbBufferSize As Long, pbBuffer As Any) As Long
    Public Declare PtrSafe Function IWICBitmap_Lock_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, prcLock As WICRect, ByVal flags As WICBitmapLockFlags, ppILock As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmap_SetPalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICBitmap_SetResolution_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal DpiX As Double, ByVal DpiY As Double) As Long
    Public Declare PtrSafe Function IWICColorContext_InitializeFromMemory_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, pbBuffer As Any, ByVal cbNormalSize As Long) As Long
    Public Declare PtrSafe Function IWICComponentFactory_CreateMetadataWriterFromReader_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIReader As stdole.IUnknown, ByRef pguidVendor As UUID, ByRef ppIWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICComponentFactory_CreateQueryWriterFromBlockWriter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIBlockWriter As stdole.IUnknown, ByRef ppIQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICComponentInfo_GetAuthor_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchAuthor As Long, ByVal wzAuthhor As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICComponentInfo_GetCLSID_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pclsid As UUID) As Long
    Public Declare PtrSafe Function IWICComponentInfo_GetFriendlyName_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchFriendlyName As Long, ByVal wzFriendlyName As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICComponentInfo_GetSpecVersion_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchSpecVersion As Long, ByVal wzSpecVersion As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICComponentInfo_GetVersion_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchVersion As Long, ByVal wzVersion As LongPtr, ByRef pcchActual As Long) As Long
    Public Declare PtrSafe Function IWICFastMetadataEncoder_Commit_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICFastMetadataEncoder_GetMetadataQueryWriter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIMetadataQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICFormatConverter_Initialize_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pISource As stdole.IUnknown, ByRef dstFormat As UUID, ByVal dither As WICBitmapDitherType, ByVal pIPalette As stdole.IUnknown, ByVal alphaThresholdPercent As Double, ByVal paletteTranslate As WICBitmapPaletteType) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapClipper_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIBitmapClipper As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapFlipRotator_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIBitmapFlipRotator As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapFromHBITMAP_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal hbitmap As LongPtr, ByVal hPalette As LongPtr, ByVal Options As WICBitmapAlphaChannelOption, ByRef ppIBitmap As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapFromHICON_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal hIcon As LongPtr, ByRef ppIBitmap As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapFromMemory_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal uiWidth As Long, ByVal uiHeight As Long, ByRef PixelFormat As UUID, ByVal cbStride As Long, ByVal cbBufferSize As Long, pbBuffer As Any, ByRef ppIBitmap As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapFromSource_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIBitmapSource As stdole.IUnknown, ByVal option As WICBitmapCreateCacheOption, ByRef ppIBitmap As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmapScaler_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIBitmapScaler As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateBitmap_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal uiWidth As Long, ByVal uiHeight As Long, ByRef PixelFormat As UUID, ByVal option As WICBitmapCreateCacheOption, ByRef ppIBitmap As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateComponentInfo_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef clsidComponent As UUID, ByRef ppIInfo As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateDecoderFromFileHandle_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal hFile As LongPtr, ByRef pguidVendor As UUID, ByVal metadataOptions As WICDecodeOptions, ppIDecoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateDecoderFromFilename_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal wzFilename As LongPtr, ByRef pguidVendor As UUID, ByVal dwDesiredAccess As Long, ByVal metadataOptions As WICDecodeOptions, ppIDecoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateDecoderFromStream_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIStream As stdole.IUnknown, ByRef pguidVendor As UUID, ByVal metadataOptions As WICDecodeOptions, ppIDecoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateEncoder_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef guidContainerFormat As UUID, ByRef pguidVendor As UUID, ppIEncoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateFastMetadataEncoderFromDecoder_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIDecoder As stdole.IUnknown, ByRef ppIFastEncoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateFastMetadataEncoderFromFrameDecode_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIFrameDecoder As stdole.IUnknown, ByRef ppIFastEncoder As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateFormatConverter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ppIFormatConverter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreatePalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateQueryWriterFromReader_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIQueryReader As stdole.IUnknown, ByRef pguidVendor As UUID, ByRef ppIQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateQueryWriter_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef guidMetadataFormat As UUID, ByRef pguidVendor As UUID, ByRef ppIQueryWriter As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICImagingFactory_CreateStream_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIWICStream As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICMetadataBlockReader_GetCount_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pcCount As Long) As Long
    Public Declare PtrSafe Function IWICMetadataBlockReader_GetReaderByIndex_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal nIndex As Long, ByRef ppIMetadataReader As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICMetadataQueryReader_GetContainerFormat_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pguidContainerFormat As UUID) As Long
    Public Declare PtrSafe Function IWICMetadataQueryReader_GetEnumerator_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef ppIEnumString As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICMetadataQueryReader_GetLocation_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cchMaxLength As Long, ByVal wzNamespace As LongPtr, ByRef pcchActualLength As Long) As Long
    Public Declare PtrSafe Function IWICMetadataQueryReader_GetMetadataByName_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal wzName As LongPtr, ByRef pvarValue As Variant) As Long
    Public Declare PtrSafe Function IWICMetadataQueryWriter_RemoveMetadataByName_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal wzName As LongPtr) As Long
    Public Declare PtrSafe Function IWICMetadataQueryWriter_SetMetadataByName_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal wzName As LongPtr, ByRef pvarValue As Variant) As Long
    Public Declare PtrSafe Function IWICPalette_GetColorCount_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pcCount As Long) As Long
    Public Declare PtrSafe Function IWICPalette_GetColors_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal cCount As Long, ByRef pColors As Long, ByRef pcActualColors As Long) As Long
    Public Declare PtrSafe Function IWICPalette_GetType_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pePaletteType As WICBitmapPaletteType) As Long
    Public Declare PtrSafe Function IWICPalette_HasAlpha_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pfHasAlpha As BOOL) As Long
    Public Declare PtrSafe Function IWICPalette_InitializeCustom_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pColors As Long, ByVal cCount As Long) As Long
    Public Declare PtrSafe Function IWICPalette_InitializeFromBitmap_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pISurface As stdole.IUnknown, ByVal cCount As Long, ByVal fAddTransparentColor As BOOL) As Long
    Public Declare PtrSafe Function IWICPalette_InitializeFromPalette_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIPalette As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICPalette_InitializePredefined_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal ePaletteType As WICBitmapPaletteType, ByVal fAddTransparentColor As BOOL) As Long
    Public Declare PtrSafe Function IWICPixelFormatInfo_GetBitsPerPixel_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef puiBitsPerPixel As Long) As Long
    Public Declare PtrSafe Function IWICPixelFormatInfo_GetChannelCount_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef puiChannelCount As Long) As Long
    Public Declare PtrSafe Function IWICPixelFormatInfo_GetChannelMask_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal uiChannelIndex As Long, ByVal cbMaskBuffer As Long, pbMaskBuffer As Any, ByRef pcbActual As Long) As Long
    Public Declare PtrSafe Function IWICStream_InitializeFromIStream_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByVal pIStream As stdole.IUnknown) As Long
    Public Declare PtrSafe Function IWICStream_InitializeFromMemory_Proxy Lib "Windowscodecs.dll" (ByVal this As stdole.IUnknown, ByRef pbBuffer As Any, ByVal cbBufferSize As Long) As Long
    But that's all of them-- I checked the DLL exports. So you get basic functionality but far from all.

  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    Sure, look limited in scope but this is such a weird approach from windowscodecs.dll to provide exports to *COM* methods -- never seen it before (or after).

    The proxy exports should be enough for load/save StdPicture functionality though.

    cheers,
    </wqw>

  15. #15
    Fanatic Member
    Join Date
    Nov 2011
    Posts
    809

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    Would be good to get a working example of different functions etc.

  16. #16

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Cool Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    The project from the first post above is using WinRT objects to render images in a PictureBox using GDI functions, hBitmaps and device contexts, thus bridging technologies several decades apart! Here's another spinoff of this project that replaces the PictureBox with a XAML Image Control for a completely modern approach. During this process, the included WinRT TypeLib has also grown from 150KB in the first post to 2.8MB in this post and now includes all XAML controls.

    Here are some of the new features highlighted in this new project:

    - The DrawFocusRect API function no longer works with the new Image Control and has been replaced with a customizable Rectangle control which results in a much smoother selection
    - New mouse handling events grouped together under a single event procedure (no subclassing required):
    - PointerPressed (VB6 equivalent: MouseDown)
    - PointerMoved (VB6 equivalent: MouseMove), used here to resize the Selection Rectangle for cropping the image
    - PointerReleased (VB6 equivalent: MouseUp)
    - PointerWheelChanged (No native VB6 equivalent, closest match would be subclassing WM_MOUSEWHEEL)
    - The Mouse Wheel is used here for a very smooth Zoom In/Out effect by applying a Scale Transform in real time

    The rest of the functionality remains the same, you can decode from various picture formats, apply some transforms and save the result as another picture format from the supported formats list.

    The project also works in the IDE and for that purpose the ZIP archive contains the VB6.EXE.manifest file which you need to apply to the main VB6.EXE executable using either the manifest tool (MT.EXE from the Windows SDK) or Resource Hacker, whichever you prefer (both are free). Alternatively you can just compile the executable and test that instead if you don't want to edit VB6.EXE.

    Here is the demo project: BitmapEncoderXAMLIslands.zip

    Requirements: Windows 10 or later!

  17. #17
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    Can it save as *.hif or *.webp?

  18. #18

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Lightbulb Re: VB6 - Simple Picture Converter & Cropper with BitmapDecoder & BitmapEncoder Class

    HEIF yes (see post #11 above), WEBP no.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width