FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ayuda cpm hbzebra.lib
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Ayuda cpm hbzebra.lib
Posted: Wed Sep 06, 2017 06:11 AM
Hola amigos:
Tengo este código, que pinta una imagen en la pantalla. lo que no puedo es cargar la imagen a una variable para poder grabarla como archivo bmp
Gracias mil
Code (fw): Select all Collapse
function main()
local oWnd

define window oWnd
activate window oWnd on paint( BarCode( hDC ) )

return nil

function BarCode( hDC )

   local hZebra
   local cCode := "testing from fivewin"
   local hBrush := CreateSolidBrush( 0 )

   hZebra := hb_zebra_create_pdf417( cCode, NIL )
   hb_zebra_draw( hZebra, {| x, y, w, h | FillRect( hDC, { y, x, y +  h, x + w }, hBrush ) }, 5, 5, 1, 4 )

   hb_zebra_destroy( hZebra )

   deleteobject( hBrush )

return(nil)
Posts: 162
Joined: Wed Feb 22, 2017 02:19 AM
Re: Ayuda cpm hbzebra.lib
Posted: Thu Sep 07, 2017 01:16 AM
Mira yo lo hago asi

#include "fivewin.ch"
#include "codebar.ch"

static oCode, oWndP

function Main()

local oMenu

oCode := TCodeBars():New()

oMenu = BuildMenu()
**

BuildCode( CODEBAR_DATAMATRIX, "DataMatrix :-)")

* define window oWndP menu oMenu
* activate window oWndP &&ON INIT (BuildCode( CODEBAR_DATAMATRIX, "DataMatrix :-)", oWndP:end() ))

return nil

function BuildMenu()

local oMenu

menu oMenu
menuitem "CodeBar"
menu
menuitem "EAN13" action( BuildCode( CODEBAR_EAN13, "477012345678" ) )
menuitem "EAN8" action( BuildCode( CODEBAR_EAN8, "1234567" ) )
menuitem "UPCA" action( BuildCode( CODEBAR_UPCA, "01234567891" ) )
menuitem "UPCE" action( BuildCode( CODEBAR_UPCE, "123456" ) )
menuitem "CODE39" action( BuildCode( CODEBAR_CODE39, "ABC123" ) )
menuitem "ITF" action( BuildCode( CODEBAR_ITF, "1234", HB_ZEBRA_FLAG_WIDE3 ) )
menuitem "MSI" action( BuildCode( CODEBAR_MSI, "1234567", HB_ZEBRA_FLAG_CHECKSUM ) )
menuitem "CODABAR" action( BuildCode( CODEBAR_CODABAR, "40156", HB_ZEBRA_FLAG_WIDE3 ) )
menuitem "CODE93" action( BuildCode( CODEBAR_CODE93, "ABC-123" ) )
menuitem "CODE11" action( BuildCode( CODEBAR_CODE11, "12", HB_ZEBRA_FLAG_WIDE3 ) )
menuitem "CODE128" action( BuildCode( CODEBAR_CODE128, "Code 128") )
menuitem "PDF417" action( BuildCode( CODEBAR_PDF417, "PDF17" ) )
menuitem "DATAMATRIX" action( BuildCode( CODEBAR_DATAMATRIX, "DataMatrix :-)") )
endmenu
endmenu

return oMenu

function BuildCode( nCode, cCode, nFlags )

* local hDC := oWndP:GetDC()

default nFlags := 0


oCode:Reset()
if nCode < CODEBAR_PDF417
oCode:nHeightCode = oCode:nHeight - 50
oCode:nWidthCode = 1.5
else
oCode:nHeightCode = 3
oCode:nWidthCode = 1
endif
oCode:SetType( nCode )
oCode:SetCode( cCode )
oCode:SetFlags( nFlags )
oCode:Build()

* DrawBitmap( hDC, oCode:hCodeBar, 0, 0 ) && aqui lo pinta en la pantalla

DrawBitmap( oCode:hCodeBar,10, 10 ) && aqui lo mando a un archivo file.bmp de 10x10 tam
hDib := DibFromBitmap(oCode:hCodeBar )
DibWrite( "file.bmp" , hDib )

* oWndP:ReleaseDC()
* oWndP:END()

return nil
Regards.
S.I.T.U.
Sistemas Inteligentes de transporte urbano
http://www.situcr.com
oscarchacon@Situcr.com
Desarrollos BA4/B4j androide
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: Ayuda cpm hbzebra.lib
Posted: Thu Sep 07, 2017 04:55 AM

Gracias mi amigo, eso funciona perfectamente con la librería externa de zebra y con XHarbour
estoy migrando Harbour 3.2.0, que tiene la librería hbzebra y el ejemplo es el que puse arriba,, y no veo la manera de pasarlo a un file..

Un abrazo..

Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: Ayuda cpm hbzebra.lib
Posted: Thu Sep 07, 2017 08:59 AM
Yo tengo una función que te puede ser util....
Usa gdiplus y no se si te faltará alguna funcion gdiplus ( en caso de faltar pidela )
El codigo que te pongo es para qrcode pero lo he comentado y te lo he puesto para pdf417. No lo he probado con pdf417 .

Code (fw): Select all Collapse
Function DrawgdiBarcodeBMP( nLineWidth, nLineHeight, cVar, cfileName )   
   local oBmp := GDIBmp():new()

   //local hZebra := hb_zebra_create_ean13( "477012345678" )
   //LOCAL hZebra := hb_zebra_create_qrcode( cVar )
   local hZebra := hb_zebra_create_pdf417( cVar, NIL )
   LOCAL nFlags
   local nWidth, nHeight
   local hBmp, hGraf
   local hBrush  := GdiPlusNewSolidBrush( 255, 255, 255, 255 )
   local hBrush2 := GdiPlusNewSolidBrush( 255, 0, 0, 255 )

   // nLineHeight := nLineWidth

   nWidht  := hb_Zebra_GetWidth ( hZebra, nLineWidth, nLineHeight, nFlags )
   nHeight := hb_Zebra_GetHeight( hZebra, nLineWidth, nLineHeight, nFlags )


   hBmp  := GDIPLUSBMPFROMBRUSH( nWidht + 2, nHeight+2, hBrush )
   hGraf := GDIPLUSHGRAFFROMHBMP( hBmp )

   hb_zebra_draw_gdip( hZebra, hGraf, hBrush2, 1, 1, nLineWidth, nLineHeight )

   oBmp:hBmp := hBmp

   GdiPlusDeleteGraphics( hGraf )
   GdiPlusDeleteBrush( hBrush )
   GdiPlusDeleteBrush( hBrush2 )

   HB_ZEBRA_DESTROY( hZebra )

   oBmp:Save( cFileName )
   oBmp:END()


Return nil


STATIC FUNCTION hb_zebra_draw_gdip( hZebra, hGraf, hBrush, ... )

   hb_zebra_draw( hZebra, {| x, y, w, h |  GDIPLUSDRAWRECT( hGraf,,hbrush,x, y, w, h ) }, ... )

RETURN 0
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: Ayuda cpm hbzebra.lib
Posted: Sat Sep 09, 2017 01:40 PM

Gracias,,,, funciona ok,,,, y como cambio el color en gdi???
Salu2

Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: Ayuda cpm hbzebra.lib
Posted: Sat Sep 09, 2017 09:39 PM
Willi Quintana wrote:Gracias,,,, funciona ok,,,, y como cambio el color en gdi???
Salu2

Puedes utilizar los colores que necesites solo cambiandolo aqui ...
hBrush2 es el color del codebar
hbrush el color del fondo
Code (fw): Select all Collapse
local hBrush  := GdiPlusNewSolidBrush( 255, 255, 255, 255 )
local hBrush2 := GdiPlusNewSolidBrush( 255, 0, 0, 255 )
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Ayuda cpm hbzebra.lib
Posted: Sun Mar 04, 2018 03:42 PM
Mr. Mastintin, where are this functions?
Code (fw): Select all Collapse
 nWidht  := hb_Zebra_GetWidth ( hZebra, nLineWidth, nLineHeight, nFlags )
   nHeight := hb_Zebra_GetHeight( hZebra, nLineWidth, nLineHeight, nFlags )
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Ayuda cpm hbzebra.lib
Posted: Sun Mar 04, 2018 06:07 PM
Gunther

Code (fw): Select all Collapse
//------------------------------------------------------------------------------

FUNCTION hb_Zebra_GetWidth ( hZebra, nLineWidth, nLineHeight, nFlags )

LOCAL x1:= 0, y1 := 0, nBarWidth := 0, nBarHeight := 0

   IF hb_zebra_GetError( hZebra ) != 0
      RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
   ENDIF
   hb_zebra_draw ( hZebra, {| x, y, w, h | nBarWidth:=x+w-x1, nBarHeight:=y+h-y1 }, x1, y1, nLineWidth, nLineHeight, nFlags )
RETURN nBarWidth

//------------------------------------------------------------------------------

FUNCTION hb_Zebra_GetHeight (hZebra, nLineWidth, nLineHeight, nFlags )

LOCAL x1:= 0, y1 := 0, nBarWidth := 0, nBarHeight := 0

   IF hb_zebra_GetError( hZebra ) != 0
      RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
   ENDIF
   hb_zebra_draw ( hZebra, {| x, y, w, h | nBarWidth:=x+w-x1, nBarHeight:=y+h-y1 }, x1, y1, nLineWidth, nLineHeight, nFlags )
RETURN nBarHeight

//------------------------------------------------------------------------------
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Ayuda cpm hbzebra.lib
Posted: Mon Mar 05, 2018 08:40 AM

THANKS!

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Ayuda cpm hbzebra.lib
Posted: Mon Mar 05, 2018 01:17 PM

Christobal, please try QR-Code with data "aa1"! You can see, that the last block is not to see! It seems as a bug in zebra. DATAMATRIX is ok.

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Ayuda cpm hbzebra.lib
Posted: Mon Mar 05, 2018 02:42 PM
Sorry, I do not understand well

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Ayuda cpm hbzebra.lib
Posted: Mon Mar 05, 2018 03:09 PM
Cristobal, please try with this code! The code are made ok, but the function hb_zebra_Getwidth(...) returns wrong width-result. I found, that this behavoir is on mode "alphanumeric" in the QR-sourcecode but not in all cases.

Code (fw): Select all Collapse
Function DrawgdiBarcodeBMP( cVar, cBmp, nWidth )
   local oBmp , hZebra
   LOCAL nFlags
   local nLineWidth := 10
   local nWidth_temp //:= 177*nLineWidth
   local hBmp, hGraf
   local hBrush  := GdiPlusNewSolidBrush( 255, 255, 255, 255 )
   local hBrush2 := GdiPlusNewSolidBrush( 255, 0, 0, 0 )

   DEFAULT cBmp := ".\QR.bmp" , nWidth := 200
  hZebra := hb_zebra_create_qrcode( cVar , nFlags)
   nWidth_temp := hb_Zebra_GetWidth ( hZebra, nLineWidth, nLineWidth, nFlags )
    oBmp := GDIBmp():new()
    hBmp  := GDIPLUSBMPFROMBRUSH( nWidth_temp, nWidth_temp, hBrush )
    hGraf := GDIPLUSHGRAFFROMHBMP( hBmp )
    hb_zebra_draw( hZebra, {| x, y, w, h |  GDIPLUSDRAWRECT( hGraf,,hbrush2,x, y, w, h ) },0,0,nLineWidth, nLineWidth, nFlags )
    GdiPlusDeleteGraphics( hGraf )
HB_ZEBRA_DESTROY( hZebra )
GdiPlusDeleteBrush( hBrush )
GdiPlusDeleteBrush( hBrush2 )
oBmp:hBmp := hBmp
oBmp:Save( cBmp )
oBmp:END()

return if(file(cBmp),cBmp,"")
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Ayuda cpm hbzebra.lib
Posted: Mon Mar 05, 2018 04:20 PM

Look your mail

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces

Continue the discussion