I can load an image, but the width it retrieves is a huge number. It looks like a random number taken from memory somewhere. If I call FIGetWidth() twice, the program crashes.
Const FIF_UNKNOWN=-1 Const FIF_BMP=0 Const FIF_ICO=1 Const FIF_JPEG=2 Const FIF_JNG=3 Const FIF_KOALA=4 Const FIF_LBM=5 Const FIF_MNG=6 Const FIF_PBM=7 Const FIF_PBMRAW=8 Const FIF_PCD=9 Const FIF_PCX=10 Const FIF_PGM=11 Const FIF_PGMRAW=12 Const FIF_PNG=13 Const FIF_PPM=14 Const FIF_PPMRAW=15 Const FIF_RAS=16 Const FIF_TARGA=17 Const FIF_TIFF=18 Const FIF_WBMP=19 Const FIF_PSD=20 Const FIF_CUT=21 Const FIF_IFF = FIF_LBM Const FIF_XBM=22 Const FIF_DDS=24 Const FIC_MINISWHITE=0 ' Min value is white Const FIC_MINISBLACK=1 ' Min value is black Const FIC_RGB=2 ' RGB Color model Const FIC_PALETTE=3 ' Color map indexed Const FIC_RGBALPHA=4 ' RGB Color model with alpha channel Const FIC_CMYK=5 ' CMYK Color model Global FI_HLIB Global FIGetFileType:Int(file$z,defaulttype:Int) Global FIGetFIFFromFilename:Int(file$z) Global FILoad:Int(ImageType:Int,file$z,Mode:Int) Global FIGetWidth:Int(fibitmap:Int) Global FIGetHeight:Int(fibitmap:Int) Global FIGetBits:Int(fibitmap:Int) Global FIGetDepth:Int(fibitmap:Int) Global FIGetPitch:Int(fibitmap:Int) Global FIConvertToRawBits(dest:Byte Ptr,FIBITMAP%,Pitch%,Depth%,RedMask%,GreenMask%,BlueMask%,TopDown%) Global FIUnload:Int(fibitmap:Int) Function FIInit() ProgramLog "Initializing FreeImage library..." If FI_HLIB Return FI_HLIB FI_HLIB=LoadLibraryA(CurrentDir()+""+"FreeImage.dll") If FI_HLIB FIGetFileType=getprocaddress(FI_HLIB,"_FreeImage_GetFileType@8") FIGetFIFFromFilename=getprocaddress(FI_HLIB,"_FreeImage_GetFIFFromFilename@4") FILoad=getprocaddress(FI_HLIB,"_FreeImage_Load@12") FIGetWidth=getprocaddress(FI_HLIB,"_FreeImage_GetWidth@4") FIGetHeight=getprocaddress(FI_HLIB,"_FreeImage_GetHeight@4") FIGetBits=getprocaddress(FI_HLIB,"_FreeImage_GetBits@4") FIGetDepth=getprocaddress(FI_HLIB,"_FreeImage_GetBPP@4") FIGetPitch=getprocaddress(FI_HLIB,"_FreeImage_GetPitch@4") FIConvertToRawBits=getprocaddress(FI_HLIB,"_FreeImage_ConvertToRawBits@32") FIUnload=getprocaddress(FI_HLIB,"_FreeImage_Unload@4") If Not FIGetFileType fail=True If Not FIGetWidth fail=True If Not FIGetHeight fail=True If Not FIGetDepth fail=True If Not FIGetPitch fail=True If Not FILoad fail=True If Not FIGetBits fail=True If fail freelibrary FI_HLIB FI_HLIB=0 Else Return FI_HLIB EndIf EndIf ProgramLog "Failed to initialize FreeImage library",1 EndFunction Function FILoadPixmap:tpixmap(file$) Local pixmap:tpixmap If Not FIInit() Return ftype=FIGetFileType(file,0) If ftype=-1 ftype=FIGetFIFFromFilename(file) If ftype=-1 Return EndIf fibitmap=FILoad(ftype,file,0) If Not fibitmap Return 'pixels=FIGetBits(fibitmap) width=FIGetWidth(fibitmap) Notify width 'height=FIGetHeight(fibitmap) 'depth=FIGetDepth(fibitmap) 'pitch=FIGetPitch(fibitmap) 'Notify width+" x "+height+" x "+depth+" x "+pitch 'Select depth ' Case 8 ' RedMask=$F800 ' GreenMask=$7E0 ' BlueMask=$1F ' format=PF_A8 ' Case 16 ' RedMask=$7C00 ' GreenMask=$3E0 ' BlueMask=$1F ' format=PF_RGB888 ' depth=24 ' pitch=width*3 ' Case 24 ' RedMask=$FF0000 ' GreenMask=$FF00 BlueMask=$FF ' format=PF_RGB888 ' Case 32 ' redmask=$FF0000 ' greenmask=$FF00 ' bluemask=$FF ' format=PF_RGBA8888 'EndSelect 'pixmap:tpixmap=CreatePixmap(width,height,format) 'FIConvertToRawBits pixmap.pixelptr(0,0),fibitmap,pitch,depth,redmask,greenmask,bluemask,0 'FIUnload fibitmap Return pixmap End Function Function FIEnd() If FI_HLIB FreeLibrary FI_HLIB FI_HLIB=0 EndIf EndFunction