Page 1 of 1

Probando PNG Reader

PostPosted: Tue May 18, 2010 4:44 am
by Daniel Garcia-Gil
Nueva caracteristica de la funcion para leer archivos PNG

now level transparences (alpha channel) estan soportados

para Harbour http://www.sitasoft.net/fivewin/lib/harbour/fwpngh.lib
para xHarbour http://www.sitasoft.net/fivewin/lib/xharbour/fwpngx.lib

samples
para Harbour http://www.sitasoft.net/fivewin/samples/tpngh.rar
para xHarbour http://www.sitasoft.net/fivewin/samples/tpngx.rar

Codigo
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 ), oBmp:HasAlpha(), oBmp:Refresh() ) 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
   define button prompt "HasAlpha" of oBar action( MsgInfo( oBmp:HasAlpha() ) ) CENTER
   define button prompt "level" of oBar action( oBmp:nAlphaLevel += 50, 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
 

Re: Probando PNG Reader

PostPosted: Tue May 18, 2010 4:46 am
by Daniel Garcia-Gil
Se puede hacer pruebas con la clase BtnBmp, sustituyendo en el Method LoadBitmap esta porcion de codigo
Code: Select all  Expand view

   if ! Empty( cBmpFile1 )
      if File( cBmpFile1 )
         if Upper( Right( cBmpFile1, 3 ) ) == "PNG"
            ::hBitmap1  = FWOpenPngFile( cBmpFile1 )
            ::hPalette1 = 0
         else
            ::cBmpFile1 = cBmpFile1
            aBmpPal     = PalBmpRead( ::GetDC(), cBmpFile1 )
            ::hBitmap1  = aBmpPal[ 1 ]
            ::hPalette1 = aBmpPal[ 2 ]
         endif
         ::HasAlpha( ::hBitmap1, BTN_UP )
//         ::ReleaseDC()
      endif
   endif


solo para pruebas, se usa la imagen Nro 1 desde archivo

Re: Probando PNG Reader

PostPosted: Tue May 18, 2010 4:20 pm
by softruz
Muy bueno, pero al compilar con Harbour me dan los siguientes errores:

Error: Unresolved external '_crc32' referenced from Z:\SOFTWARE\HARBOUR\FUE\FWPNGH.LIB|PNG
Error: Unresolved external '_inflateReset' referenced from Z:\SOFTWARE\HARBOUR\FUE\FWPNGH.LIB|PNG
Error: Unresolved external '_inflateInit_' referenced from Z:\SOFTWARE\HARBOUR\FUE\FWPNGH.LIB|PNGREAD
Error: Unresolved external '_inflate' referenced from Z:\SOFTWARE\HARBOUR\FUE\FWPNGH.LIB|PNGRUTIL
Error: Unresolved external '_inflateEnd' referenced from Z:\SOFTWARE\HARBOUR\FUE\FWPNGH.LIB|PNGREAD
Error: Unresolved external '_HB_FUN_ISGDIOBJECT' referenced from Z:\SOFTWARE\HARBOUR\FUE\CTBMSIGP.OBJ

¿Por que puede ser ?

Re: Probando PNG Reader

PostPosted: Tue May 18, 2010 7:18 pm
by Daniel Garcia-Gil
Softruz


debes enlazar para xharbour zlib.lib y para Harbour hbzlib.lib, disculpa olvide mencionarlo

para resolver IsGdiObject()

coloca esto

Code: Select all  Expand view
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

HB_FUNC( ISGDIOBJECT )
{
    hb_retl( IsGDIObject( ( HANDLE ) hb_parnl( 1 ) ) );
}
#pragma ENDDUMP

Re: Probando PNG Reader

PostPosted: Wed May 19, 2010 7:26 am
by softruz
Gracias, tenemos el hbzlib.lib para Harbour.

Un Saludo.

Re: Probando PNG Reader

PostPosted: Wed Nov 23, 2011 4:53 pm
by Francisco Horta
Daniel
Gracias por tu apoyo, revise el ejemplo y no pude adaptarlo a la ribbon, para leer .png asi utilizo la ribbon

@ 5, 5 ADD BUTTON ::oBoton PROMPT "Punto de Venta" BITMAP ::cDirBmps+"pdv48.BMP" ;
GROUP ::oGrupo SIZE 80,90 ROUND ROUNDSIZE 2 BORDER

intente hacerle asi pero no encuentra las variables:

::oBoton:hBitmap := Loadpng(::cDirBmps+"pdv48.png")
::oBoton:cBitmap := Loadpng(::cDirBmps+"pdv48.png")

a ver si me echas la mano para poner .png en los botones,
gracias como siempre por tu apoyo
saludos
paco