Page 1 of 1

Ayuda cpm hbzebra.lib

PostPosted: Wed Sep 06, 2017 6:11 am
by Willi Quintana
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: Select all  Expand view

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)

 

Re: Ayuda cpm hbzebra.lib

PostPosted: Thu Sep 07, 2017 1:16 am
by Busmatic_wpb
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

Re: Ayuda cpm hbzebra.lib

PostPosted: Thu Sep 07, 2017 4:55 am
by Willi Quintana
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..

Re: Ayuda cpm hbzebra.lib

PostPosted: Thu Sep 07, 2017 8:59 am
by mastintin
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: Select all  Expand view


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



 

Re: Ayuda cpm hbzebra.lib

PostPosted: Sat Sep 09, 2017 1:40 pm
by Willi Quintana
Gracias,,,, funciona ok,,,, y como cambio el color en gdi???
Salu2

Re: Ayuda cpm hbzebra.lib

PostPosted: Sat Sep 09, 2017 9:39 pm
by mastintin
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: Select all  Expand view


local hBrush  := GdiPlusNewSolidBrush( 255, 255, 255, 255 )
local hBrush2 := GdiPlusNewSolidBrush( 255, 0, 0, 255 )

 

Re: Ayuda cpm hbzebra.lib

PostPosted: Sun Mar 04, 2018 3:42 pm
by byte-one
Mr. Mastintin, where are this functions?
Code: Select all  Expand view
nWidht  := hb_Zebra_GetWidth ( hZebra, nLineWidth, nLineHeight, nFlags )
   nHeight := hb_Zebra_GetHeight( hZebra, nLineWidth, nLineHeight, nFlags )

Re: Ayuda cpm hbzebra.lib

PostPosted: Sun Mar 04, 2018 6:07 pm
by cnavarro
Gunther

Code: Select all  Expand view

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

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

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

 

Re: Ayuda cpm hbzebra.lib

PostPosted: Mon Mar 05, 2018 8:40 am
by byte-one
THANKS!

Re: Ayuda cpm hbzebra.lib

PostPosted: Mon Mar 05, 2018 1:17 pm
by byte-one
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.

Re: Ayuda cpm hbzebra.lib

PostPosted: Mon Mar 05, 2018 2:42 pm
by cnavarro
Sorry, I do not understand well

Image

Re: Ayuda cpm hbzebra.lib

PostPosted: Mon Mar 05, 2018 3:09 pm
by byte-one
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: Select all  Expand view
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,"")

Re: Ayuda cpm hbzebra.lib

PostPosted: Mon Mar 05, 2018 4:20 pm
by cnavarro
Look your mail