Re: Simplest way to display Image???

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here's a function that will create a proper Win32Lib DIB from a CxImage object. I just took createDIB(), ripped out the EuBmp guts and stuffed in some CxImage calls. Enjoy! smile

global function createDIBFromCXImage( atom image )
 
    sequence info, pal 
    integer width, height, bitsPer, colors, headerSize 
    atom mset, memBits, memBitmapInfo, at, hdc, hDIB 
     
    mset = w32new_memset() 
     
    -- get the dib info 
    info = CXI_GetDIB( image ) 
    memBits = info[1] 
    width   = info[2] 
    height  = info[3] 
    bitsPer = info[4] 
     
    -- get the palette 
    pal = CXI_GetPalette( image ) 
     
    -- determine number of colors 
    colors = length( pal ) 
     
    -- determine the header size 
    headerSize = SIZEOF_BITMAPINFOHEADER + (SIZEOF_RGBQUAD * colors) 
     
    -- allocate memory for DIB 
    memBitmapInfo = w32acquire_mem( mset, headerSize ) 
    w32set_memory( memBitmapInfo, ID_BITMAPINFOHEADER, 
        {SIZEOF_BITMAPINFOHEADER, width, height, 1, bitsPer, 0, 0, 0, 0, colors, 0} ) 
     
    -- get the address of the first rgb tuple 
    at = w32address( memBitmapInfo, bmiColors ) 
 
    -- copy the pal to memory 
    for i = 1 to colors do 
 
        -- store values 
        w32store( at, rgbRed, pal[i][1] ) 
        w32store( at, rgbGreen, pal[i][2] ) 
        w32store( at, rgbBlue, pal[i][3] ) 
        w32store( at, rgbReserved, 0 ) 
 
        -- move to next quad 
        at += SIZEOF_RGBQUAD 
 
    end for 
     
    -- Get the screen's device context. 
    hdc = getDC( Screen ) 
 
    -- Create the DIB. 
    hDIB = w32Func( xCreateDIBitmap, { 
            hdc, 
            w32address( memBitmapInfo, bmiHeader ), 
            CBM_INIT, 
            memBits, 
            memBitmapInfo, 
            DIB_RGB_COLORS} ) 
 
    -- release the screen dc 
    releaseDC( Screen ) 
 
    -- Free memory 
    w32release_mem( mset ) 
 
    trackObject( {-1,kBitmapObject}, hDIB, ForProgram ) 
 
    return hDIB 
end function 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu