Re: Simplest way to display Image???
- Posted by ghaberek (admin) Jun 22, 2009
- 1167 views
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!
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