Using GDI+ you can load BMP, GIF, TIFF, JPEG and PNG files. This code loads the image and then converts it to a StdPicture object to use it in Visual Basic controls.
' ----==== API Declarations ====---- Private Type GdiplusStartupInput GdiplusVersion AsLong DebugEventCallback AsLong SuppressBackgroundThread AsLong SuppressExternalCodecs AsLong End Type PrivateDeclareFunction GdiplusStartup()Function GdiplusStartup Lib"GDIPlus" ( _ token AsLong, _ inputbuf As GdiplusStartupInput, _ OptionalByVal outputbuf AsLong=0) AsLong PrivateDeclareFunction GdiplusShutdown()Function GdiplusShutdown Lib"GDIPlus" ( _ ByVal token AsLong) AsLong PrivateDeclareFunction GdipCreateBitmapFromFile()Function GdipCreateBitmapFromFile Lib"GDIPlus" ( _ ByVal filename AsLong, _ bitmap AsLong) AsLong PrivateDeclareFunction GdipDisposeImage()Function GdipDisposeImage Lib"GDIPlus" ( _ ByVal image AsLong) AsLong PrivateDeclareFunction GdipCreateHBITMAPFromBitmap()Function GdipCreateHBITMAPFromBitmap Lib"GDIPlus" ( _ ByVal bitmap AsLong, _ hbmReturn AsLong, _ ByVal background AsLong) AsLong Private Type PICTDESC cbSizeOfStruct AsLong picType AsLong hgdiObj AsLong hPalOrXYExt AsLong End Type Private Type IID Data1 AsLong Data2 AsInteger Data3 AsInteger Data4(0To7) AsByte End Type PrivateDeclareSub OleCreatePictureIndirect()Sub OleCreatePictureIndirect Lib"oleaut32.dll" ( _ lpPictDesc As PICTDESC, _ riid As IID, _ ByVal fOwn AsBoolean, _ lplpvObj AsObject) '------------------------------------------------------ ' Procedure : LoadPicturePlus ' Purpose : Loads an image using GDI+ ' Returns : The image loaded in a StdPicture object ' Author : Eduardo A. Morcillo '------------------------------------------------------ ' PublicFunction LoadPicturePlus()Function LoadPicturePlus( _ ByVal filename AsString) As StdPicture Dim tSI As GdiplusStartupInput Dim lGDIP AsLong Dim lRes AsLong Dim lBitmap AsLong ' Initialize GDI+ tSI.GdiplusVersion =1 lRes = GdiplusStartup(lGDIP, tSI) If lRes =0Then ' Open the image file lRes = GdipCreateBitmapFromFile(StrPtr(filename), lBitmap) If lRes =0Then Dim hBitmap AsLong ' Create a GDI bitmap lRes = GdipCreateHBITMAPFromBitmap(lBitmap, hBitmap, 0) ' Create the StdPicture object Set LoadPicturePlus = HandleToPicture(hBitmap, vbPicTypeBitmap) ' Dispose the image GdipDisposeImage lBitmap EndIf ' Shutdown GDI+ GdiplusShutdown lGDIP EndIf If lRes Then Err.Raise 5, , "Cannot load file" End Function '------------------------------------------------------ ' Procedure : HandleToPicture ' Purpose : Creates a StdPicture object to wrap a GDI ' image handle '------------------------------------------------------ ' PublicFunction HandleToPicture()Function HandleToPicture( _ ByVal hGDIHandle AsLong, _ ByVal ObjectType As PictureTypeConstants, _ OptionalByVal hPal AsLong=0) As StdPicture Dim tPictDesc As PICTDESC Dim IID_IPicture As IID Dim oPicture As IPicture ' Initialize the PICTDESC structure With tPictDesc .cbSizeOfStruct =Len(tPictDesc) .picType = ObjectType .hgdiObj = hGDIHandle .hPalOrXYExt = hPal EndWith ' Initialize the IPicture interface ID With IID_IPicture .Data1 =&H7BF80981 .Data2 =&HBF32 .Data3 =&H101A .Data4(0) =&H8B .Data4(1) =&HBB .Data4(3) =&HAA .Data4(5) =&H30 .Data4(6) =&HC .Data4(7) =&HAB EndWith ' Create the object OleCreatePictureIndirect tPictDesc, IID_IPicture, _ True, oPicture ' Return the picture object Set HandleToPicture = oPicture End Function