FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Creating on memory BMP from ZEBRA barcode
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 01:47 AM
Hello,

I'm trying to create a bmp from barcode generated with zebra

Code (fw): Select all Collapse
function Main

   define window oWnd menu oMenu
     @ 5,10 BITMAP oBmp OF oWnd
     oBmp:hBitMap := CreateBitmap( "HOLA", 100, 100 )
   activate window oWnd 

return nil


static function CreateBitmap( nQRCODE, nWidth, nHeight )

   local hDC1 := GetDC( GetDesktopWindow() )
   local hDC2 := CreateCompatibleDC( hDC1 )
   local hBmp := CreateCompatibleBitmap( hDC1, nWidth, nHeight )
   local hOldBmp := SelectObject( hDC2, hBmp )
   local hBrush  := CreateSolidBrush( 0 )
   local hBack   := CreateSolidBrush( CLR_WHITE )
   local hcode

   hCode := hb_zebra_create_code39( nQRCODE )
   FillRect( hDC2, { 0, 0, nHeight, nWidth }, hBack )
   Rectangle( hDC2, 0, 0, 20, 20 )
   hb_zebra_draw( hCode, {| x, y, w, h | FillRect( hDC2, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, nWidth, nHeight )
      
   SelectObject( hDC2, hOldBmp )
   DeleteDC( hDC2 )
   ReleaseDC( hDC1 )
   DeleteObject( hBrush )
   DeleteObject( hBack )

return hBmp


You can see a Rectangle function, if I comment the hb_zebra_draw, I can obtain the rectangle, but if I use the hb_zebra_draw the result is a black rectangle

Some idea?

regards

Marcelo
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 04:36 PM

Hola

comenta Rectangle( hDC2, 0, 0, 20, 20 ) y prueba

Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 06:32 PM

Estimado Daniel,

gracias por responder, obtengo el mismo cuadrado negro, aumente el rectangle solo para saber que algo hacia, tienes alguna idea

saludos cordiales

Marcelo

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 07:22 PM
hace tiempo que hice una clase... no se si funcione para el codigo actual... puedes probarla


CH
Code (fw): Select all Collapse
#include "hbzebra.ch" 

#define CODEBAR_EAN13          1
#define CODEBAR_EAN8           2
#define CODEBAR_UPCA           3
#define CODEBAR_UPCE           4
#define CODEBAR_ITF            5
#define CODEBAR_MSI            6
#define CODEBAR_CODABAR        7
#define CODEBAR_CODE11         8
#define CODEBAR_CODE39         9
#define CODEBAR_CODE93         10
#define CODEBAR_CODE128        11
#define CODEBAR_PDF417         12
#define CODEBAR_DATAMATRIX     13
#define CODEBAR_QRCODE         14

#define CODEBAR_TYPE           1
#define CODEBAR_BLOCK          2

#define DEFAULT_CODEBAR        CODEBAR_PDF417

clase
Code (fw): Select all Collapse
#include "fivewin.ch"
#include "codebar.ch"

CLASS TCodeBars
   
   DATA aTypes HIDDEN
   
   DATA cCode
   DATA nFlags
   
   DATA hCodeBar
   DATA hData
   
   DATA nType, nWidth, nHeight, nWidthCode, nHeightCode

   METHOD New()
   METHOD End()     INLINE  DeleteObject( ::hCodeBar ),  If( ::hData != NIL, hb_zebra_destroy( ::hData ), )
   
   METHOD DefError( nError )
   METHOD SetCode( cCode )
   METHOD SetFlags( nFlags )
   METHOD SetType( cnType )
   METHOD Reset()   INLINE ::End()
   METHOD Build()   
   METHOD Rebuild() INLINE ::Reset(), ::Build()
   
   
ENDCLASS

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

METHOD New( nWidth, nHeight, nWidthCode, nHeightCode, cnType, cCode, nFlags ) CLASS TCodeBars 

   DEFAULT nWidth := 200,;
           nHeight := 100,;
           nWidthCode := 1,;
           nHeightCode := 3
   

   ::aTypes = { { "EAN13"      , {| | hb_zebra_create_ean13( ::cCode, ::nFlags )      } },;
                { "EAN8"       , {| | hb_zebra_create_ean8( ::cCode, ::nFlags )       } },;
                { "UPCA"       , {| | hb_zebra_create_upca( ::cCode, ::nFlags )       } },;
                { "UPCE"       , {| | hb_zebra_create_upce( ::cCode, ::nFlags )       } },;
                { "ITF"        , {| | hb_zebra_create_itf( ::cCode, ::nFlags )        } },;
                { "MSI"        , {| | hb_zebra_create_msi( ::cCode, ::nFlags )        } },;
                { "CODABAR"    , {| | hb_zebra_create_codabar( ::cCode, ::nFlags )    } },;
                { "CODE11"     , {| | hb_zebra_create_code11( ::cCode, ::nFlags )     } },;
                { "CODE39"     , {| | hb_zebra_create_code39( ::cCode, ::nFlags )     } },;
                { "CODE93"     , {| | hb_zebra_create_code93( ::cCode, ::nFlags )     } },;
                { "CODE128"    , {| | hb_zebra_create_code128( ::cCode, ::nFlags )    } },;
                { "PDF417"     , {| | NIL /*hb_zebra_create_pdf417( ::cCode, ::nFlags )     */} },;
                { "DATAMATRIX" , {| | hb_zebra_create_datamatrix( ::cCode, ::nFlags ) } },;
                { "QRCODE"     , {| | hb_zebra_create_qrcode( ::cCode, ::nFlags )     } } }
   
   ::nWidth  = nWidth
   ::nHeight = nHeight 
   ::nWidthCode  = nWidthCode
   ::nHeightCode = nHeightCode
   
   ::SetType( cnType )
   ::SetCode( cCode )
   ::SetFlags( nFlags )


return Self

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

METHOD Build() CLASS TCodeBars

   local hBmpOld
   local hDCDesk := GetDC( GetDesktopWindow() )
   local hDCMem  := CreateCompatibleDC( hDCDesk )
   local hBrush  := CreateSolidBrush( 0 )
   local hBack   := CreateSolidBrush( CLR_WHITE )

   ::hCodeBar = CreateCompatibleBitMap( hDCDesk, ::nWidth, ::nHeight )
   hBmpOld    = SelectObject( hDCMem, ::hCodeBar )   

   ::hData := Eval( ::aTypes[ ::nType ][ CODEBAR_BLOCK ] )
   
   ::DefError()
   FillRect( hDCMem, { 0, 0, ::nHeight, ::nWidth }, hBack )
   hb_zebra_draw( ::hData, {| x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, ::nWidthCode, ::nHeightCode )
   
   //DrawText( hDCMem, ::cCode, { ::nHeight - 15, 0, ::nHeight, ::nWidth }, 1 )
   
   SelectObject( hDCMem, hBmpOld )
   ReleaseDC( GetDesktopWindow(), hDCDesk )
   DeleteDC( hDCMem )
   DeleteObject( hBrush )
   DeleteObject( hBack )
   
   
return NIL

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

METHOD SetCode( cCode ) CLASS TCodeBars

   if ! Empty( cCode )
      if ValType( cCode ) != "C"
         cCode = cValToChar( cCode )
      endif 
      ::cCode = cCode
   endif

return NIL

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

METHOD SetFlags( nFlags ) CLASS TCodeBars

   ::nFlags = nFlags

return NIL

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

METHOD SetType( cnType ) class TCodeBars

   local cType

   if ( ( cType := ValType( cnType ) )$"CN" )
      if cType == "N" 
         if cnType > 0 .and. cnType < 15
            ::nType = cnType
         endif
      else
         ::nType = AScan( ::aTypes, {| a | a[ CODEBAR_TYPE ] == Upper( cnType ) } ) 
      endif
   else
      ::nType = DEFAULT_CODEBAR
   endif 
   
return NIL   

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

METHOD DefError( ) CLASS TCodeBars
   local oError
   local nError := 0
   
   if ::hData != NIL 
      nError = hb_zebra_geterror( ::hData ) 
   endif
   
   
   if nError != 0
      hb_zebra_destroy( ::hData )

      oError := ErrorNew()
      oError:SubSystem   = "TCODEBARS"
      oError:SubCode     = nError
      oError:Severity    = 2
      
      Eval( ErrorBlock(), oError )   
   
   endif

RETURN nil

#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>

HB_FUNC( CREATECOMPATIBLEBITMAP ) // hDC, nWidth, nHeight
{
   hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}

#pragma ENDDUMP


EJEMPLO
Code (fw): Select all Collapse
#include "fivewin.ch"
#include "codebar.ch" 

static oCode, oWnd

function Main

   local oMenu
   
   oCode := TCodeBars():New(500,500)
   
   oMenu = BuildMenu()
   
   define window oWnd menu oMenu
   activate window oWnd 

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 :)") )
           menuitem "QR-CODE"    action( BuildCode( CODEBAR_QRCODE,     "http://danielgarciagil.com/") )
        endmenu
   endmenu
   
return oMenu

function BuildCode( nCode, cCode, nFlags )

   local hDC := oWnd:GetDC()
   local oPrn

   default nFlags := 0
   
   oCode:Reset()
   if nCode < CODEBAR_PDF417
      oCode:nHeightCode = oCode:nHeight - 50
      oCode:nWidthCode  = 1.5
   else
      if nCode == CODEBAR_QRCODE
         oCode:nHeightCode = 3
         oCode:nWidthCode  = 3
      else
         oCode:nHeightCode = 3
         oCode:nWidthCode  = 1
      endif
   endif
   oCode:SetType( nCode )
   oCode:SetCode( cCode )
   oCode:SetFlags( nFlags )
   oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   PRINT oPrn NAME "Qr code print" PREVIEW
      PAGE
         *Drawbitmap( oPrn, oCode:hCodeBar, 100, 100)
         *oPrn:SayImage( 100, 100, oCode:hCodeBar, 300, 300 )
         *oPrn:SayBitmap( 100, 100, oCode:hCodeBar, 300, 300 )

         Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         oPrn:Say( 500, 100, "This is a test" )
      ENDPAGE
   ENDPRINT
   
   oWnd:ReleaseDC()
   
return nil
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 07:39 PM

Daniel
Falta el fichero .ch

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: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 07:50 PM
cnavarro wrote:Daniel
Falta el fichero .ch


listo :-)
Gracias
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Mon Apr 14, 2014 08:03 PM

Tu ejemplo y la clase funciona perfecto
Gracias Daniel

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: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Tue Apr 15, 2014 02:19 AM

Gracias Daniel,

pude generar un BMP al vuelo con tu clase

saludos

Marcelo

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Wed Aug 19, 2015 03:13 PM
Daniel porfa, como hago usando HBZEBRA, puedo salvar en formatos .JPG, BMP, PNG, ICO, etc?

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "codebar.ch" 

static oCode, oWnd

function Main

   local oMenu
   
   oCode := TCodeBars():New(500,500)
   
   oMenu = BuildMenu()
   
   define window oWnd menu oMenu
   activate window oWnd 

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 :)") )
           menuitem "QR-CODE"    action( BuildCode( CODEBAR_QRCODE,     "http://danielgarciagil.com/") )
        endmenu
   endmenu
   
return oMenu

function BuildCode( nCode, cCode, nFlags )

   local hDC := oWnd:GetDC()
   local oPrn

   default nFlags := 0
   
   oCode:Reset()
   if nCode < CODEBAR_PDF417
      oCode:nHeightCode = oCode:nHeight - 50
      oCode:nWidthCode  = 1.5
   else
      if nCode == CODEBAR_QRCODE
         oCode:nHeightCode = 3
         oCode:nWidthCode  = 3
      else
         oCode:nHeightCode = 3
         oCode:nWidthCode  = 1
      endif
   endif
   oCode:SetType( nCode )
   oCode:SetCode( cCode )
   oCode:SetFlags( nFlags )
   oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   PRINT oPrn NAME "Qr code print" PREVIEW
      PAGE
         *Drawbitmap( oPrn, oCode:hCodeBar, 100, 100)
         *oPrn:SayImage( 100, 100, oCode:hCodeBar, 300, 300 )
         *oPrn:SayBitmap( 100, 100, oCode:hCodeBar, 300, 300 )

         Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         oPrn:Say( 500, 100, "This is a test" )
      ENDPAGE
   ENDPRINT
   
   oWnd:ReleaseDC()
   
return nil   

// CLASSE


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

CLASS TCodeBars
   
   DATA aTypes HIDDEN
   
   DATA cCode
   DATA nFlags
   
   DATA hCodeBar
   DATA hData
   
   DATA nType, nWidth, nHeight, nWidthCode, nHeightCode

   METHOD New()
   METHOD End()     INLINE  DeleteObject( ::hCodeBar ),  If( ::hData != NIL, hb_zebra_destroy( ::hData ), )
   
   METHOD DefError( nError )
   METHOD SetCode( cCode )
   METHOD SetFlags( nFlags )
   METHOD SetType( cnType )
   METHOD Reset()   INLINE ::End()
   METHOD Build()   
   METHOD Rebuild() INLINE ::Reset(), ::Build()
   
   
ENDCLASS

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

METHOD New( nWidth, nHeight, nWidthCode, nHeightCode, cnType, cCode, nFlags ) CLASS TCodeBars 

   DEFAULT nWidth := 200,;
           nHeight := 100,;
           nWidthCode := 1,;
           nHeightCode := 3
   

   ::aTypes = { { "EAN13"      , {| | hb_zebra_create_ean13( ::cCode, ::nFlags )      } },;
                { "EAN8"       , {| | hb_zebra_create_ean8( ::cCode, ::nFlags )       } },;
                { "UPCA"       , {| | hb_zebra_create_upca( ::cCode, ::nFlags )       } },;
                { "UPCE"       , {| | hb_zebra_create_upce( ::cCode, ::nFlags )       } },;
                { "ITF"        , {| | hb_zebra_create_itf( ::cCode, ::nFlags )        } },;
                { "MSI"        , {| | hb_zebra_create_msi( ::cCode, ::nFlags )        } },;
                { "CODABAR"    , {| | hb_zebra_create_codabar( ::cCode, ::nFlags )    } },;
                { "CODE11"     , {| | hb_zebra_create_code11( ::cCode, ::nFlags )     } },;
                { "CODE39"     , {| | hb_zebra_create_code39( ::cCode, ::nFlags )     } },;
                { "CODE93"     , {| | hb_zebra_create_code93( ::cCode, ::nFlags )     } },;
                { "CODE128"    , {| | hb_zebra_create_code128( ::cCode, ::nFlags )    } },;
                { "PDF417"     , {| | NIL /*hb_zebra_create_pdf417( ::cCode, ::nFlags )     */} },;
                { "DATAMATRIX" , {| | hb_zebra_create_datamatrix( ::cCode, ::nFlags ) } },;
                { "QRCODE"     , {| | hb_zebra_create_qrcode( ::cCode, ::nFlags )     } } }
   
   ::nWidth  = nWidth
   ::nHeight = nHeight 
   ::nWidthCode  = nWidthCode
   ::nHeightCode = nHeightCode
   
   ::SetType( cnType )
   ::SetCode( cCode )
   ::SetFlags( nFlags )


return Self

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

METHOD Build() CLASS TCodeBars

   local hBmpOld
   local hDCDesk := GetDC( GetDesktopWindow() )
   local hDCMem  := CreateCompatibleDC( hDCDesk )
   local hBrush  := CreateSolidBrush( 0 )
   local hBack   := CreateSolidBrush( CLR_WHITE )

   ::hCodeBar = CreateCompatibleBitMap( hDCDesk, ::nWidth, ::nHeight )
   hBmpOld    = SelectObject( hDCMem, ::hCodeBar )   

   ::hData := Eval( ::aTypes[ ::nType ][ CODEBAR_BLOCK ] )
   
   ::DefError()
   FillRect( hDCMem, { 0, 0, ::nHeight, ::nWidth }, hBack )
   hb_zebra_draw( ::hData, {| x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, ::nWidthCode, ::nHeightCode )
   
   //DrawText( hDCMem, ::cCode, { ::nHeight - 15, 0, ::nHeight, ::nWidth }, 1 )
   
   SelectObject( hDCMem, hBmpOld )
   ReleaseDC( GetDesktopWindow(), hDCDesk )
   DeleteDC( hDCMem )
   DeleteObject( hBrush )
   DeleteObject( hBack )
   
   
return NIL

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

METHOD SetCode( cCode ) CLASS TCodeBars

   if ! Empty( cCode )
      if ValType( cCode ) != "C"
         cCode = cValToChar( cCode )
      endif 
      ::cCode = cCode
   endif

return NIL

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

METHOD SetFlags( nFlags ) CLASS TCodeBars

   ::nFlags = nFlags

return NIL

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

METHOD SetType( cnType ) class TCodeBars

   local cType

   if ( ( cType := ValType( cnType ) )$"CN" )
      if cType == "N" 
         if cnType > 0 .and. cnType < 15
            ::nType = cnType
         endif
      else
         ::nType = AScan( ::aTypes, {| a | a[ CODEBAR_TYPE ] == Upper( cnType ) } ) 
      endif
   else
      ::nType = DEFAULT_CODEBAR
   endif 
   
return NIL   

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

METHOD DefError( ) CLASS TCodeBars
   local oError
   local nError := 0
   
   if ::hData != NIL 
      nError = hb_zebra_geterror( ::hData ) 
   endif
   
   
   if nError != 0
      hb_zebra_destroy( ::hData )

      oError := ErrorNew()
      oError:SubSystem   = "TCODEBARS"
      oError:SubCode     = nError
      oError:Severity    = 2
      
      Eval( ErrorBlock(), oError )   
   
   endif

RETURN nil

#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>

HB_FUNC( CREATECOMPATIBLEBITMAP ) // hDC, nWidth, nHeight
{
   hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}

#pragma ENDDUMP



Gracias, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Thu Aug 20, 2015 01:13 PM
Master Daniel, está correcto? Gracias.

// Usando HBZEBRA.LIB para gerar QRCODE.
Code (fw): Select all Collapse
#Include "Fivewin.ch"
#Include "Codebar.ch"

STATIC oCode, oWnd, cCode

//function Main()
FUNCTION QrCode( SEQUENC )

   local oMenu
   
   oCode := TCodeBars():New(500,500)

   // SEQUENC := ( "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" )

   IF ( SEQUENC ) = NIL

      cCode := "CODIGO INVALIDO OU VAZIO..."

      ? cCode

      RETURN NIL

   ENDIF

   cCode := ALLTRIM( SEQUENC )

   // Direto sem MENU
   // oMenu = BuildMenu()  // nao quero menu
   
   //DEFINE WINDOW oWnd menu oMenu
   //-> Invisibilizo a Janela
   DEFINE WINDOW oWnd FROM -10, -10 TO -5, -5


   // ATIVO, APENAS PARA GERAR SEM MOSTRAR
   ACTIVATE WINDOW oWnd ; // nCode     // cCode
      ON INIT( BuildCode( CODEBAR_QRCODE, cCode  ), oWnd: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 :)") )

           //menuitem "QR-CODE"    action( BuildCode( CODEBAR_QRCODE,     "http://danielgarciagil.com/") )
                                 // nCode            // cCode
           menuitem "QR-CODE"    ;
              action( BuildCode( CODEBAR_QRCODE,     "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" ) )

        endmenu
   endmenu
   
return oMenu
*/

function BuildCode( nCode, cCode, nFlags )

   local oVent
   local hDC := oWnd:GetDC()
   local oPrn
   LOCAL hDib
   LOCAL hBmp := CreateCompatibleBitmap( hDC, 150, 50 )  // 150, 50
   LOCAL hOldBmp := SelectObject( hDC, hBmp )

   default nFlags := 0
   
   oCode:Reset()

   if nCode < CODEBAR_PDF417
      oCode:nHeightCode = oCode:nHeight - 50
      oCode:nWidthCode  = 1.5
   else

      if nCode == CODEBAR_QRCODE

         oCode:nHeightCode =  3   // altura  // 7.23 PAGINA CHEIA
         oCode:nWidthCode  =  3   // Largura // 7.23 PAGIAN CHEIA

      else

         oCode:nHeightCode = 3
         oCode:nWidthCode  = 1

      endif
   endif

   oCode:SetType( nCode )
   oCode:SetCode( cCode )
   oCode:SetFlags( nFlags )
   oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   hDib := DibFromBitmap( oCode:hCodeBar )

   DibWrite( "QRCODE.BMP" , hDib )

   // HBZEBRA, SOMENTE GERA EM *.BMP, uma pena.
   // DibWrite( "QRCODE.JPG" , hDib )  // mesmo tamanho que o *.BMP ??

   GloBalFree( hDib )


   // SE EU QUISER IMPRIMIR.
   /*
   PRINT oPrn NAME "Qr code print" PREVIEW
      PAGE
         *Drawbitmap( oPrn, oCode:hCodeBar, 100, 100)
         *oPrn:SayImage( 100, 100, oCode:hCodeBar, 300, 300 )
         *oPrn:SayBitmap( 100, 100, oCode:hCodeBar, 300, 300 )

         //Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         //oPrn:Say( 500, 100, "This is a test" )


      ENDPAGE
   ENDPRINT
   */
   
   oWnd:ReleaseDC()
   
return nil   

// CLASSE

/*
#include "fivewin.ch"
#include "codebar.ch"
*/

CLASS TCodeBars
   
   DATA aTypes HIDDEN
   
   DATA cCode
   DATA nFlags
   
   DATA hCodeBar
   DATA hData
   
   DATA nType, nWidth, nHeight, nWidthCode, nHeightCode

   METHOD New()
   METHOD End()     INLINE  DeleteObject( ::hCodeBar ),  If( ::hData != NIL, hb_zebra_destroy( ::hData ), )
   
   METHOD DefError( nError )
   METHOD SetCode( cCode )
   METHOD SetFlags( nFlags )
   METHOD SetType( cnType )
   METHOD Reset()   INLINE ::End()
   METHOD Build()   
   METHOD Rebuild() INLINE ::Reset(), ::Build()
   
   
ENDCLASS

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

METHOD New( nWidth, nHeight, nWidthCode, nHeightCode, cnType, cCode, nFlags ) CLASS TCodeBars 

   DEFAULT nWidth := 200,;
           nHeight := 100,;
           nWidthCode := 1,;
           nHeightCode := 3
   

   ::aTypes = { { "EAN13"      , {| | hb_zebra_create_ean13( ::cCode, ::nFlags )      } },;
                { "EAN8"       , {| | hb_zebra_create_ean8( ::cCode, ::nFlags )       } },;
                { "UPCA"       , {| | hb_zebra_create_upca( ::cCode, ::nFlags )       } },;
                { "UPCE"       , {| | hb_zebra_create_upce( ::cCode, ::nFlags )       } },;
                { "ITF"        , {| | hb_zebra_create_itf( ::cCode, ::nFlags )        } },;
                { "MSI"        , {| | hb_zebra_create_msi( ::cCode, ::nFlags )        } },;
                { "CODABAR"    , {| | hb_zebra_create_codabar( ::cCode, ::nFlags )    } },;
                { "CODE11"     , {| | hb_zebra_create_code11( ::cCode, ::nFlags )     } },;
                { "CODE39"     , {| | hb_zebra_create_code39( ::cCode, ::nFlags )     } },;
                { "CODE93"     , {| | hb_zebra_create_code93( ::cCode, ::nFlags )     } },;
                { "CODE128"    , {| | hb_zebra_create_code128( ::cCode, ::nFlags )    } },;
                { "PDF417"     , {| | NIL /*hb_zebra_create_pdf417( ::cCode, ::nFlags )     */} },;
                { "DATAMATRIX" , {| | hb_zebra_create_datamatrix( ::cCode, ::nFlags ) } },;
                { "QRCODE"     , {| | hb_zebra_create_qrcode( ::cCode, ::nFlags )     } } }
   
   ::nWidth  = nWidth
   ::nHeight = nHeight 
   ::nWidthCode  = nWidthCode
   ::nHeightCode = nHeightCode
   
   ::SetType( cnType )
   ::SetCode( cCode )
   ::SetFlags( nFlags )

return Self

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

METHOD Build() CLASS TCodeBars

   local hBmpOld
   local hDCDesk := GetDC( GetDesktopWindow() )
   local hDCMem  := CreateCompatibleDC( hDCDesk )
   local hBrush  := CreateSolidBrush( 0 )
   local hBack   := CreateSolidBrush( CLR_WHITE )

   ::hCodeBar = CreateCompatibleBitMap( hDCDesk, ::nWidth, ::nHeight )
   hBmpOld    = SelectObject( hDCMem, ::hCodeBar )   

   ::hData := Eval( ::aTypes[ ::nType ][ CODEBAR_BLOCK ] )
   
   ::DefError()
   FillRect( hDCMem, { 0, 0, ::nHeight, ::nWidth }, hBack )
   hb_zebra_draw( ::hData, {| x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, ::nWidthCode, ::nHeightCode )
   
   //DrawText( hDCMem, ::cCode, { ::nHeight - 15, 0, ::nHeight, ::nWidth }, 1 )
   
   SelectObject( hDCMem, hBmpOld )
   ReleaseDC( GetDesktopWindow(), hDCDesk )
   DeleteDC( hDCMem )
   DeleteObject( hBrush )
   DeleteObject( hBack )
   
   
return NIL

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

METHOD SetCode( cCode ) CLASS TCodeBars

   if ! Empty( cCode )
      if ValType( cCode ) != "C"
         cCode = cValToChar( cCode )
      endif 
      ::cCode = cCode
   endif

return NIL

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

METHOD SetFlags( nFlags ) CLASS TCodeBars

   ::nFlags = nFlags

return NIL

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

METHOD SetType( cnType ) class TCodeBars

   local cType

   if ( ( cType := ValType( cnType ) )$"CN" )
      if cType == "N" 
         if cnType > 0 .and. cnType < 15
            ::nType = cnType
         endif
      else
         ::nType = AScan( ::aTypes, {| a | a[ CODEBAR_TYPE ] == Upper( cnType ) } ) 
      endif
   else
      ::nType = DEFAULT_CODEBAR
   endif 
   
return NIL   

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

METHOD DefError( ) CLASS TCodeBars
   local oError
   local nError := 0
   
   if ::hData != NIL 
      nError = hb_zebra_geterror( ::hData ) 
   endif
   
   
   if nError != 0
      hb_zebra_destroy( ::hData )

      oError := ErrorNew()
      oError:SubSystem   = "TCODEBARS"
      oError:SubCode     = nError
      oError:Severity    = 2
      
      Eval( ErrorBlock(), oError )   
   
   endif

RETURN nil

#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>

HB_FUNC( CREATECOMPATIBLEBITMAP ) // hDC, nWidth, nHeight
{
   hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}

#pragma ENDDUMP


/*
// CODEBAR.CH


#include "hbzebra.ch" 

#define CODEBAR_EAN13          1
#define CODEBAR_EAN8           2
#define CODEBAR_UPCA           3
#define CODEBAR_UPCE           4
#define CODEBAR_ITF            5
#define CODEBAR_MSI            6
#define CODEBAR_CODABAR        7
#define CODEBAR_CODE11         8
#define CODEBAR_CODE39         9
#define CODEBAR_CODE93         10
#define CODEBAR_CODE128        11
#define CODEBAR_PDF417         12
#define CODEBAR_DATAMATRIX     13
#define CODEBAR_QRCODE         14

#define CODEBAR_TYPE           1
#define CODEBAR_BLOCK          2

#define DEFAULT_CODEBAR        CODEBAR_PDF417
*/

// FIM DO PROGRAMA - 26/08/2015


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Wed Aug 26, 2015 03:49 PM

Up!

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Fri Aug 28, 2015 09:57 AM

Añandiendo sobre este tópico
Daniel, sería posible publicar e. hbzebra.ch ?
No lo he visto en el código.

Gracias :)

Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Fri Jun 15, 2018 03:08 AM

Buena noche..
Estoy probando el ejemplo, y me arroja este error

Error: Unresolved external '_HB_FUN_HB_ZEBRA_CREATE_QRCODE' referenced from C:\FWH\ZEBRA\OBJ\TCODEBAR.OBJ

fwh 15.2 +
xHarbour 1.2.3 Intl. (SimpLex) (Build 20180609)
Copyright 1999-2018, http://www.xharbour.org http://www.harbour-project.org/

Gracias

Johnson Russi

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Fri Oct 19, 2018 05:17 AM

Dear All,

I got samples of HBZEBRA.LIB but I'm not success to create BMP file.

How can I create BMP file from HBZEBRA.LIB?

Thanks in advance for any help.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Creating on memory BMP from ZEBRA barcode
Posted: Thu Nov 01, 2018 12:18 PM

May I have any sample?

Thanks in advance.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)