Page 1 of 1

Testing PNG reader

PostPosted: Tue May 18, 2010 4:43 am
by Daniel Garcia-Gil
New features to PNG reader

now level transparences (alpha channel) is supported

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

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

Code
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: Testing PNG reader

PostPosted: Tue May 18, 2010 4:48 am
by Daniel Garcia-Gil
We can do test with BtnBmp class, replace inside Method LoadBitmap this part
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


only for test, we used the image 1 from files

Re: Testing PNG reader

PostPosted: Wed May 19, 2010 2:11 am
by lailton.webmaster
Hi Daniel,

Today i did test with your lib to test PNG file.

well, now we can use png without dll, more yet have a problem,

look for this:

Image
Image
Image
Image
Think that need new type of display a image file. only converte to hBitmap think that
problem with transparency will continue.

what you think about this ?

Thanks.

Re: Testing PNG reader

PostPosted: Wed May 19, 2010 3:40 am
by Daniel Garcia-Gil
Lailton...

are you using the last test???

because the last test have 7 Button in buttonbar, check test source code ( hasalpha, level )

please download new .zip and .lib file

Re: Testing PNG reader

PostPosted: Wed May 19, 2010 4:37 am
by lailton.webmaster
Perfect.

i tryed with old function.

thanks Daniel, Perfect job. :lol:

Re: Testing PNG reader

PostPosted: Wed May 19, 2010 5:17 am
by fraxzi
Hello Daniel,

So we dont need freeimage.dll when using your lib? That's great!


Regards,
Frances

Re: Testing PNG reader

PostPosted: Wed May 19, 2010 10:26 am
by Daniel Garcia-Gil
Frances

fraxzi wrote:So we dont need freeimage.dll when using your lib?


no need freeimage.dll

Re: Testing PNG reader

PostPosted: Thu May 20, 2010 2:49 am
by fraxzi
Daniel Garcia-Gil wrote:Frances

fraxzi wrote:So we dont need freeimage.dll when using your lib?


no need freeimage.dll




Dear Daniel,

Great! Very nice job.

my best regards,
Frances

Re: Testing PNG reader

PostPosted: Thu May 20, 2010 2:08 pm
by Patricio Avalos Aguirre
Hola

como se debería usar con BTNBMP

Code: Select all  Expand view
REDEFINE BTNBMP oBmp1 ID 4001 OF oDlg FILENAME "C:\FWH\bitmaps\hires\windows media player.png";
action .t.
 

Re: Testing PNG reader

PostPosted: Thu May 20, 2010 2:35 pm
by lailton.webmaster
Patricio Avalos Aguirre wrote:Hola

como se debería usar con BTNBMP

Code: Select all  Expand view
REDEFINE BTNBMP oBmp1 ID 4001 OF oDlg FILENAME "C:\FWH\bitmaps\hires\windows media player.png";
action .t.
 


tiene que alterar la classe btnbmp, en lo metodo LoadBitmap()

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


Somiente esso e usar dela forma que tu estas hacendo en lo REDEFINE :D

Re: Testing PNG reader

PostPosted: Thu May 20, 2010 5:30 pm
by Patricio Avalos Aguirre
Gracias funciona perfecto..

ahora en tu ejemplo tienes en comentario el // ::ReleaseDC()
en mi original clase está si que la deje de esta manera

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

Re: Testing PNG reader

PostPosted: Thu May 20, 2010 5:33 pm
by lailton.webmaster
Sem problemas,

somiente segui o que a foi passado pelo Daniel,
acredito que la deferença es devido la version de fivewin :)

:roll:

Re: Testing PNG reader

PostPosted: Tue Aug 21, 2012 6:55 am
by ryugarai27
Hi Daniel,

I tried to compile your code and encountered the following error:

Unresolved external '_HB_FUN_ISGDIOBJECT' referenced from Z:\obj\main.obj

I am using FWH 9.01 + BCC55 + xHB1.1

Thanks.
ryugarai27

Re: Testing PNG reader

PostPosted: Tue Aug 21, 2012 4:52 pm
by Lailton
Ryugarai,

Add to your prg

Code: Select all  Expand view
#pragma BEGINDUMP
 #include "windows.h"
 #include "hbapi.h"
 #ifdef __FLAT__
  BOOL IsGDIObject( HGDIOBJ hobj ){  return ( BOOL ) GetObjectType( hobj ); }
 #endif
 HB_FUNC( ISGDIOBJECT ){    hb_retl( IsGDIObject( ( HANDLE ) hb_parnl( 1 ) ) ); }
#pragma ENDDUMP

Re: Testing PNG reader

PostPosted: Fri Aug 24, 2012 7:24 am
by ryugarai27
Lailton,

Thanks!

ryugarai27