Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Load image from string/memory buffer using FreeImage.DLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load image from string/memory buffer using FreeImage.DLL

    Code:
    ' FreeImage.INC
    '
    ' Small implementation of the FreeImage library.
    ' This file contains only calls for loading a FreeImage supported image.
    ' The library is loaded on demand.
    ' Download FreeImage at: [url="http://www.6ixsoft.com"]http://www.6ixsoft.com[/url]
     
    ' Original .INC file translated by Edwin Knoppert
    ' Modifications for loading an image from a string/memory buffer by Bernard Ertl
    '   with thanks to Steve Hutchesson for the MemCopyD function
     
    $DllName = "FREEIMAGE.DLL"  
      
    %FIF_UNKNOWN    = -1
    %FIF_BMP        = 0
    %FIF_ICO        = 1
    %FIF_JPEG       = 2
    %FIF_JNG        = 3
    %FIF_KOALA      = 4
    %FIF_LBM        = 5
    %FIF_MNG        = 6
    %FIF_PBM        = 7
    %FIF_PBMRAW     = 8
    %FIF_PCD        = 9
    %FIF_PCX        = 10
    %FIF_PGM        = 11
    %FIF_PGMRAW     = 12
    %FIF_PNG        = 13
    %FIF_PPM        = 14
    %FIF_PPMRAW     = 15
    %FIF_RAS        = 16
    %FIF_TARGA      = 17
    %FIF_TIFF       = 18    'Compression: PackBits, uncompressed, NO LZW
    %FIF_WBMP       = 19
    %FIF_PSD        = 20
    %FIF_CUT        = 21
    %FIF_IFF        = %FIF_LBM
     
    '====================================================
    ' Internal use
    '====================================================
     
    TYPE FreeImage_Proc
     
        pGetVersion             AS DWORD
        pGetCopyrightMessage    AS DWORD
        pGetFileType            AS DWORD
        pLoad                   AS DWORD
        pFree                   AS DWORD
        pGetInfoHeader          AS DWORD
        pGetBits                AS DWORD
        pGetInfo                AS DWORD
     
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    '@ Added by Bernard Ertl 8/11/2002
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        pGetFileTypeFromHandle  AS DWORD
        pLoadFromHandle         AS DWORD
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     
    END TYPE
     
    TYPE FreeImage_Params
     
        hLib    AS LONG
        DProcs  AS FreeImage_Proc
     
    END TYPE
     
     
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    '@ Added by Bernard Ertl 8/11/2002
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    TYPE FreeImage_IO
     
       read_proc  AS DWORD     'POINTER TO the FUNCTION used TO READ DATA
       write_proc AS DWORD     'POINTER TO the FUNCTION used TO WRITE DATA
       seek_proc  AS DWORD     'POINTER TO the FUNCTION used TO SEEK
       tell_proc  AS DWORD     'POINTER TO the FUNCTION used TO aquire the current position
     
    END TYPE
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     
    GLOBAL FreeImage_Param AS FreeImage_Params
     
    DECLARE FUNCTION FreeImg_GetVersion() AS DWORD
    DECLARE FUNCTION FreeImg_GetCopyrightMessage() AS DWORD
    DECLARE FUNCTION FreeImg_GetFileType( szFileName AS ASCIIZ, BYVAL nSize AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_Load( BYVAL fif AS LONG, szFileName AS ASCIIZ, BYVAL nflags AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_Free( BYVAL hfidib AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_GetInfoHeader( BYVAL hfidib AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_GetBits( BYVAL hfidib AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_GetInfo( BYVAL hfidib AS LONG ) AS LONG
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    '@ Added by Bernard Ertl 8/11/2002
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    DECLARE FUNCTION FreeImg_GetFileTypeFromHandle( io AS FreeImage_IO, BYVAL fhandle AS DWORD, BYVAL nSize AS LONG ) AS LONG
    DECLARE FUNCTION FreeImg_LoadFromHandle( BYVAL fif AS LONG, io AS FreeImage_IO, BYVAL fhandle AS DWORD, BYVAL nflags AS LONG ) AS LONG
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     
     
    '====================================================
    ' Public use
    '====================================================
     
    ' This call loads the FreeImage library, an optional library name may be set.
    ' All other procedures will call this procedure anyway.
    ' The lib is loaded only once.
    FUNCTION FreeImage_LoadLibrary() AS LONG
     
        DIM dp AS FreeImage_Params
        LOCAL sOptLibName AS STRING
     
        IF FreeImage_Param.hLib THEN
            FUNCTION = 1
            EXIT FUNCTION
        END IF
     
        sOptLibName = $DllName
        FreeImage_Param.hLib = LoadLibrary( BYVAL STRPTR( sOptLibName ) )
     
        SELECT CASE FreeImage_Param.hLib
           CASE 0 TO 32
              FreeImage_Param.hLib = 0
              EXIT FUNCTION
        END SELECT
     
        FreeImage_Param.DProcs.pGetVersion            = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pGetCopyrightMessage   = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pGetFileType           = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pLoad                  = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pFree                  = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pGetInfoHeader         = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pGetBits               = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pGetInfo               = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
     
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    '@ Added by Bernard Ertl 8/11/2002
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        FreeImage_Param.DProcs.pGetFileTypeFromHandle = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
        FreeImage_Param.DProcs.pLoadFromHandle        = GetProcAddress( FreeImage_Param.hLib, "[email protected]" )
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     
        ' Are all calls available IN the DLL?
        IF INSTR( PEEK$( VARPTR( FreeImage_Param.DProcs ), LEN( FreeImage_Proc ) ), MKL$( 0 ) ) THEN
     
            FreeLibrary FreeImage_Param.hLib
            FreeImage_Param = dp
     
        END IF
     
        FUNCTION = ISTRUE( FreeImage_Param.hLib )
     
    END FUNCTION
     
    ' You should free the library on application exit.
    FUNCTION FreeImage_FreeLibrary() AS LONG
     
        DIM dp AS FreeImage_Params
     
        IF FreeImage_Param.hLib = 0 THEN EXIT FUNCTION
     
        FreeLibrary FreeImage_Param.hLib
     
        FreeImage_Param = dp
     
        FUNCTION = 1
     
    END FUNCTION
     
    '====================================================
    ' FreeImage API
    '====================================================
    FUNCTION FreeImage_GetVersion() AS STRING
     
        DIM pszText AS ASCIIZ PTR
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetVersion USING FreeImg_GetVersion() TO pszText
        IF pszText = 0 THEN EXIT FUNCTION
     
        FUNCTION = @pszText
     
    END FUNCTION
     
    FUNCTION FreeImage_GetCopyrightMessage() AS STRING
     
        DIM pszText AS ASCIIZ PTR
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetCopyrightMessage USING FreeImg_GetCopyrightMessage() TO pszText
        IF pszText = 0 THEN EXIT FUNCTION
     
        FUNCTION = @pszText
     
    END FUNCTION
     
    FUNCTION FreeImage_GetFileType( BYVAL sFileName AS STRING, BYVAL nSize AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetFileType USING FreeImg_GetFileType( BYVAL STRPTR( sFileName ), nSize ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_Load( BYVAL fif AS LONG, BYVAL sFileName AS STRING, BYVAL nflags AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pLoad USING FreeImg_Load( fif, BYVAL STRPTR( sFileName ), nFlags ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_Free( BYVAL hfidib AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pFree USING FreeImg_Free( hfidib ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_GetInfoHeader( BYVAL hfidib AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetInfoHeader USING FreeImg_GetInfoHeader( hfidib ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_GetBits( BYVAL hfidib AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetBits USING FreeImg_GetBits( hfidib ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_GetInfo( BYVAL hfidib AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetInfo USING FreeImg_GetInfo( hfidib ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    ' Wrapper to load image and create a Windows bitmap handle (DIB)
    ' You should use DeleteObject() API to destroy this handle.
    ' hDC might be 0 to use the screen device.
    FUNCTION FreeImage_LoadDIB( BYVAL hDC AS LONG, BYVAL sFileName AS STRING ) AS LONG
     
        DIM hUsehDC     AS LONG
        DIM nFileType   AS LONG
        DIM hDIB        AS LONG
        DIM hfidib      AS LONG
     
        sFileName = TRIM$( sFileName )
        IF sFileName = "" THEN EXIT FUNCTION
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        nFileType = FreeImage_GetFileType( sFileName, 0 )
        hfidib = FreeImage_Load( nFileType, sFileName, 0 )
     
        IF hfidib THEN
     
            hUsehDC = hDC
            IF hDC = 0 THEN hUsehDC = GetDC( %HWND_DESKTOP )
     
            hDIB = CreateDIBitmap( _
                  hUsehDC _
                , BYVAL FreeImage_GetInfoHeader( hfidib ) _
                , %CBM_INIT _
                , BYVAL FreeImage_GetBits( hfidib ) _
                , BYVAL FreeImage_GetInfo( hfidib ) _
                , %DIB_RGB_COLORS _
                )
     
            IF hDC = 0 THEN ReleaseDC %HWND_DESKTOP, hUsehDC
     
            FreeImage_Free hfidib
        END IF
     
        FUNCTION = hDIB
     
    END FUNCTION
     
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    '@ Added by Bernard Ertl 8/11/2002
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    FUNCTION FreeImage_GetFileTypeFromHandle( io AS FreeImage_IO, BYVAL fhandle AS DWORD, BYVAL nSize AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pGetFileTypeFromHandle USING FreeImg_GetFileTypeFromHandle( io, fHandle, nSize ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    FUNCTION FreeImage_LoadFromHandle( BYVAL fif AS LONG, io AS FreeImage_IO, BYVAL fHandle AS DWORD, BYVAL nFlags AS LONG ) AS LONG
     
        DIM nResult AS LONG
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        CALL DWORD FreeImage_Param.DProcs.pLoadFromHandle USING FreeImg_LoadFromHandle( fif, io, fHandle, nFlags ) TO nResult
     
        FUNCTION = nResult
     
    END FUNCTION
     
    %SEEK_SET  = 0
    %SEEK_CUR  = 1
    %SEEK_END  = 2
     
    GLOBAL AddrImageBuffer AS DWORD
    GLOBAL LastByteImageBuffer AS DWORD
     
    'MemCopyD courtesy of Steve Hutchesson
    SUB MemCopyD (BYVAL src AS DWORD, BYVAL dst AS DWORD, BYVAL ln AS LONG)
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' Assumptions : ln <= LEN(src) <= LEN(dst)
    ' Result = dst = src
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
          #REGISTER NONE
     
          ! cld
     
          ! mov  esi, src
          ! mov  edi, dst
          ! mov  ecx, ln
     
          ! shr  ecx, 2
          ! rep  movsd
     
          ! mov  ecx, ln
          ! and  ecx, 3
          ! rep  movsb
     
    END SUB
     
    FUNCTION read_proc( BYVAL addrBuffer AS DWORD, BYVAL dsize AS DWORD, BYVAL dCount AS DWORD, BYVAL fHandle AS DWORD ) AS DWORD      'FUNCTION used TO READ DATA
     
       LOCAL BytesToCopy AS DWORD
     
       IF AddrImageBuffer + dSize * dCount > LastByteImageBuffer THEN
          BytesToCopy = LastByteImageBuffer - AddrImageBuffer
       ELSE
          BytesToCopy = dSize * dCount
       END IF
       MemCopyD AddrImageBuffer, addrBuffer, BytesToCopy
       AddrImageBuffer = AddrImageBuffer + BytesToCopy
       FUNCTION = BytesToCopy
     
    END FUNCTION
     
    FUNCTION write_proc( sBuffer AS ASCIIZ, BYVAL dsize AS DWORD, BYVAL dCount AS DWORD, BYVAL fHandle AS DWORD ) AS DWORD     'FUNCTION used TO WRITE DATA
     
       FUNCTION = dSize
     
    END FUNCTION
     
    FUNCTION seek_proc( BYVAL fHandle AS DWORD, BYVAL lOffset AS LONG, BYVAL lOrigin AS LONG ) AS DWORD     'FUNCTION used TO SEEK
     
       SELECT CASE AS LONG lOrigin
          CASE %SEEK_END
             EXIT FUNCTION
          CASE %SEEK_SET
             AddrImageBuffer = fHandle + lOffset
          CASE ELSE
             AddrImageBuffer = AddrImageBuffer + lOffset
       END SELECT
     
    END FUNCTION
     
    FUNCTION tell_proc( BYVAL fHandle AS DWORD) AS DWORD     'FUNCTION used TO aquire the current position
     
       IF fHandle <= AddrImageBuffer THEN EXIT FUNCTION
     
       FUNCTION = AddrImageBuffer - fHandle
     
    END FUNCTION
     
    FUNCTION FreeImage_LoadDIBFromHandle( BYVAL hDC AS LONG, BYVAL fHandle AS DWORD ) AS LONG
     
        DIM hUsehDC     AS LONG
        DIM nFileType   AS LONG
        DIM hDIB        AS LONG
        DIM hfidib      AS LONG
        LOCAL io AS FreeImage_IO
     
        IF fHandle = 0 THEN EXIT FUNCTION
     
        IF FreeImage_LoadLibrary = 0 THEN EXIT FUNCTION
     
        io.read_proc  = CODEPTR( read_proc)
        io.write_proc = CODEPTR( write_proc)
        io.tell_proc  = CODEPTR( tell_proc)
        io.seek_proc  = CODEPTR( seek_proc)
     
        nFileType = FreeImage_GetFileTypeFromHandle( io, fHandle, 0 )
        hfidib = FreeImage_LoadFromHandle( nFileType, io, fHandle, 0 )
     
        IF hfidib THEN
     
            hUsehDC = hDC
            IF hDC = 0 THEN hUsehDC = GetDC( %HWND_DESKTOP )
     
            hDIB = CreateDIBitmap( _
                  hUsehDC _
                , BYVAL FreeImage_GetInfoHeader( hfidib ) _
                , %CBM_INIT _
                , BYVAL FreeImage_GetBits( hfidib ) _
                , BYVAL FreeImage_GetInfo( hfidib ) _
                , %DIB_RGB_COLORS _
                )
     
            IF hDC = 0 THEN ReleaseDC %HWND_DESKTOP, hUsehDC
     
            FreeImage_Free hfidib
        END IF
     
        FUNCTION = hDIB
     
    END FUNCTION
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    Code:
    'LoadFromMemory.BAS
     
    'Original code by Edwin Knoppert - modified by Bernard Ertl
     
    #COMPILE EXE
     
    OPTION EXPLICIT
     
    #INCLUDE "win32api.inc"
    #INCLUDE ".\FreeImage.inc"
     
    GLOBAL hBitmap AS LONG
     
    CALLBACK FUNCTION DlgProc() AS LONG
     
        DIM a AS LONG
     
       STATIC pic AS BITMAP
       STATIC hDCBmp AS LONG, hDC AS LONG, hBmpOld AS LONG
       LOCAL hDCPaint AS LONG
       LOCAL ps AS PAINTSTRUCT
       LOCAL tRect AS RECT
     
        SELECT CASE CBMSG
        CASE %WM_INITDIALOG
     
            IF hBitmap THEN
               hDC = getDC ( CBHNDL)
               IF hDC <> 0 THEN hDCBmp = CreateCompatibleDC( hDC )
               hBmpOld = SelectObject( hDCBmp, hBitmap )
               GetObject hBitmap, SIZEOF( pic ), pic
            END IF
     
        CASE %WM_COMMAND
     
            SELECT CASE CBCTL
              CASE %IDCANCEL
                DIALOG END CBHNDL, 0
            END SELECT
     
        CASE %WM_DESTROY
             IF  hBitmap < > 0  THEN
                SelectObject hDCBmp, hBmpOld
                DeleteDC hDCBmp
             END IF
             ReleaseDC CBHNDL, hDC
     
        CASE %WM_SIZING
           InvalidateRect CBHNDL, BYVAL 0, 1
     
          CASE %WM_PAINT
             hDCPaint = BeginPaint( CBHNDL, ps )
             IF hDCPaint = %NULL THEN EXIT FUNCTION
             IF hBitmap <> 0 THEN
     
                 GetClientRect CBHNDL, tRect
     
                 IF pic.bmWidth < tRect.nRight AND pic.bmHeight < tRect.nBottom THEN
                    BitBlt hDCPaint, 0, 0, pic.bmWidth, pic.bmHeight  , hDCBmp, 0, 0, %SRCCOPY
                 ELSEIF pic.bmWidth > tRect.nRight AND pic.bmHeight < tRect.nBottom THEN
                    StretchBlt hDCPaint, 0, 0, tRect.nRight, pic.bmHeight, hDCBmp, 0, 0, pic.bmWidth, pic.bmHeight, %SRCCOPY
                 ELSEIF pic.bmWidth < tRect.nRight AND pic.bmHeight > tRect.nBottom THEN
                    StretchBlt hDCPaint, 0, 0, pic.bmWidth, tRect.nBottom, hDCBmp, 0, 0, pic.bmWidth, pic.bmHeight, %SRCCOPY
                 ELSE 'pic.bmWidth > tRect.nRight AND pic.bmHeight > tRect.nBottom THEN
                    StretchBlt hDCPaint, 0, 0, tRect.nRight, tRect.nBottom , hDCBmp, 0, 0, pic.bmWidth, pic.bmHeight, %SRCCOPY
                 END IF
             END IF
             EndPaint CBHNDL, ps
        END SELECT
     
    END FUNCTION
     
    FUNCTION WINMAIN ( BYVAL hCurInstance  AS LONG, _
                       BYVAL hPrevInstance AS LONG, _
                       lpszCmdLine         AS ASCIIZ PTR, _
                       BYVAL nCmdShow      AS LONG ) AS LONG
     
        DIM a       AS LONG
        DIM hDlg    AS LONG
        DIM Result  AS LONG
        DIM hDC AS LONG
        DIM hfidib AS LONG
        LOCAL Buffer AS STRING
        LOCAL fHandle AS DWORD
        LOCAL sFile AS STRING
     
        IF FreeImage_LoadLibrary = 0 THEN
            MSGBOX "FreeImage not loaded"
            EXIT FUNCTION
        END IF
     
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        sFile = "" '<< Add a full, valid path & filename here.
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     
        OPEN sFile FOR BINARY AS #1
        GET$ #1, LOF( 1), Buffer
        CLOSE #1
     
        fHandle = STRPTR( Buffer)
        'The following MUST be defined for loading from memory...
        AddrImageBuffer = fHandle
        LastByteImageBuffer = AddrImageBuffer + LEN( Buffer)
     
        hBitmap = FreeImage_LoadDIBFromHandle( 0, fHandle )  '<< Use this to load from a string/memory buffer
     
    '    hBitmap = FreeImage_LoadDIB( 0, sFile )   '<< Use this to load from a file
     
        IF hBitmap = 0 THEN
            MSGBOX "Image not loaded"
            EXIT FUNCTION
        END IF
     
        DIALOG NEW 0, "FreeImage",,, 340, 280 _
            ,  %WS_OVERLAPPED _
            OR %WS_SYSMENU _
            OR %WS_MINIMIZEBOX _
            OR %WS_MAXIMIZEBOX _
            OR %WS_THICKFRAME _
            OR %WS_CLIPSIBLINGS _
            OR %WS_CLIPCHILDREN _
            TO hDlg
     
        IF hDlg = 0 THEN EXIT FUNCTION
     
        DIALOG SHOW MODAL hDlg CALL DlgProc TO Result
     
        IF hBitmap THEN DeleteObject hBitmap
     
        FreeImage_FreeLibrary
     
        FUNCTION = 1
     
    END FUNCTION
    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

    Comment

    Working...
    X