convert PNG to BMP from code

convert PNG to BMP from code

Postby Daniel Garcia-Gil » Sun Mar 28, 2010 2:41 am

Hello all

wrapper function from LibPng to convert PNG Image to BMP image from code...
we can read PNG image and show like bitmap image, the level transparences ( alpha channel) is not support :(
(this is only for test)

for Harbour:
Link: hbzlib.lib
LIB: http://www.sitasoft.net/fivewin/lib/harbour/fwpngh.lib
sample: http://www.sitasoft.net/fivewin/samples/tpngh.rar

for xHarbour:
Link: zlib.lib
LIB: http://www.sitasoft.net/fivewin/lib/xharbour/fwpngx.lib
sample: http://www.sitasoft.net/fivewin/samples/tpngx.rar

code sample
Code: Select all  Expand view


#include "FiveWin.ch"

STATIC oWnd, oBmp

FUNCTION Main()
   local oBar
   local cFile := ""
   local lSetAlpha := .t.
   

   DEFINE WINDOW oWnd FROM 0,0 TO 20,50 TITLE "Test READING PNG IMAGE"
   
   define buttonbar oBar of oWnd size 48,48
   define button prompt "File" of oBar action( LoadPng( oBmp ) ) CENTER
   define button prompt "transp ON" of oBar action( oBmp:lTransparent := .T., oBmp:refresh() ) CENTER
   define button prompt "transp OFF" of oBar action( oBmp:lTransparent := .F., oBmp:refresh() ) CENTER
   define button prompt "Adjust ON" of oBar action( oBmp:lStretch := .T., oBmp:refresh() ) CENTER
   define button prompt "Adjust OFF" of oBar action( oBmp:lStretch := .F., oBmp:refresh() ) CENTER
      @ 0,0 BITMAP oBmp FILENAME cFile OF oWnd ;
         PIXEL SCROLL
      WndCenter(oWnd:hWnd)


   ACTIVATE WINDOW oWnd ;
      ON PAINT ( oBmp:aDjClient(), oBmp:ScrollAdjust() ) ;
      ON RESIZE ( oBmp:aDjClient(), oBmp:ScrollAdjust() )

RETURN ( nil )

function LoadPng( oBmp )
   
   local cFile := cGetFile( "*.png","Select File" )
   local hPng
   
   if !Empty( cFile  )
      hPng = FWOpenPngFile( cFile )
      if IsGdiObject( hPng )
         if IsGdiObject( oBmp:hBitmap )
            DeleteObject( oBmp:hBitmap )
         endif
         oBmp:hBitmap = hPng
         oBmp:Refresh()
      endif
   endif
   
return nil
 


there are some difference between H - xH, i think is library zlib in both compilers...
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 129 guests