Imprimir un JPG,

HMG en Español

Moderator: Rathinagiri

Post Reply
gdp
Posts: 36
Joined: Mon Jan 21, 2013 12:57 am
Has thanked: 1 time

Imprimir un JPG,

Post by gdp »

Hola, estimados

Gracias a los ejemplos y el generador de codigo QR que subio Roberto, , pude armara un utilitario que me genera el codigo QR , y me lo guarda en PNG,
Cuando lo abro, lo visualizo perfecto, y me lo lee sin inconenietes.
Mi problema es que al imprimirlo, sale en blanco.
He puesto aviso para ver si encuentra el archivo, lo guarde tambien como JPG, pero no logro encontrar el problema.

GRACIAS desde ya

GERARDO

Code: Select all

Private cBaseURL, cCuit, cPtoVta, cTipoCmp, cJSON, cBase64JSON


	cBaseURL    := 'https://www.afip.gob.ar/fe/qr/?p='
	cFecha      := LEFT(cFecha,4) + '-' + SUBSTR(cFecha,5,2) + '-' + RIGHT(cFecha,2)
	cCuit       := ALLTRIM(STR(nCUITEmisor))
	cPtoVta     := ALLTRIM( STR(nPdV) )
	cTipoCmp    := ALLTRIM(STR(nTipoCmp)) 
	cNroCmp     := ALLTRIM( STR(nNroCmp) )
	cImporte    := ALLTRIM( STR(nImporte) )
	cMoneda     := ALLTRIM(cMoneda)
	cCtz        := ALLTRIM(STR(nCtz))
	cTipoDocRec := ALLTRIM( STR(nTipoDocRec) )
	cNroDocRec  := ALLTRIM( STR(nNroDocRec) )
	
	* Crear Texto QR

	cJSON := '{"ver":1,"fecha":"' + cFecha + '","cuit":' + cCuit + ',"ptoVta":' + cPtoVta + ',"tipoCmp":' + cTipoCmp + ',"nroCmp":' + cNroCmp + ',"importe":' + cImporte + ',"moneda":"' + cMoneda + '","ctz":' + cCtz + ',"tipoDocRec":' + cTipoDocRec + ',"nroDocRec":' + cNroDocRec + ',"tipoCodAut":"E","codAut":' + cCodAut + '}'
	cBase64JSON := hb_base64encode( cJSON )
	cFullCode := cBaseURL + cBase64JSON
Return	
	
function CreateBarCode
   local hBitMap
   
   hBitMap := HMG_CreateBarCode( cFullCode,;
                   "QRCODE",;
                   12,;
                   12,;
                   .t.,;
                   var2,;
                   aBarColor,;
                   aBackColor,;
                   .t.,;  // checksum
                   .f.,;  // wide2_5
                   .f. )  // wide3    	
Return                   

franco
Posts: 574
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 33 times

Post by franco »

This is what I think you might need.
Not sure but worked in my brws image problem.
The png file is named jpg but is still a png file.

Code: Select all

private png := .F., pimage:= 'file.jpg'
copy file file.png to file.jpg
checkpng()
				IF png = .T.
					@ PL,118 PRINT IMAGE Pimage WIDTH 85 HEIGHT 50 type png
				ELSE
					@ PL,118 PRINT IMAGE Pimage WIDTH 85 HEIGHT 50 type jpg   
				ENDIF
				png := .F

function checkpng                      // This checks if file is png or not.
	local pho
		f:=fopen(Pimage,0)
		if f>-1
			pho :=(FREADstr(f, 10))
			fclose(f)
			*pho := upper(phfol)
			if 'PNG' $ upper(pho)
				png := .T.
			else
				png := .F.
			endif
			fclose(f)
		endif

	fclose(f)
return
All The Best,
Franco
Canada

User avatar
AUGE_OHR
Posts: 1304
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 244 times
Been thanked: 369 times

Post by AUGE_OHR »

hi,

i have run Original Sample \SAMPLES\HFCL\HMG_Zebra\hmgzebra.exe with default value
it generate EAN13.png but when load with IrfanView it does "warn" that something is wrong.

HMG_CreateBarCode() does generate File with Header "PNG"
\SOURCE\h_HMG_Zebra.Prg

Code: Select all

FUNCTION  HMG_CreateBarCode( ... )
   ...
   IF HMG_len( cImageFileName ) <> 0
      BT_BitmapSaveFile( hBitmap, cImageFileName, BT_FILEFORMAT_PNG )
      BT_BitmapRelease ( hBitmap )
      RETURN 1
   ENDIF   
RETURN hBitmap
---

i have copy Folder ZEBRA and rename HMG_CreateBarCode() to JIM_CreateBarCode() and add Parameter nType

i have try with BT_FILEFORMAT_JPG and that seems to generate "right" EAN13.JPG

---

it would be nice if Sample \SAMPLES\HFCL\HMG_Zebra\Main.Prg include all BT_FILEFORMAT_*

it need to add Parameter to \SOURCE\h_HMG_Zebra.Prg

Code: Select all

FUNCTION HMG_CreateBarCode( cCode, cType, nLineWidth, nLineHeight, lShowdigits, cImageFileName, aBarColor, aBackColor, lCheckSum, lWide2_5, lWide3 , nType )
DEFAULT nType := BT_FILEFORMAT_JPG
      ...
      BT_BitmapSaveFile( hBitmap, cImageFileName, nType )
have fun
Jimmy

User avatar
andyglezl
Posts: 1327
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 45 times
Been thanked: 150 times
Contact:

Post by andyglezl »

\HMG\3.4.4\INCLUDE\BosTaurus.ch

// BT_BMP_SAVEFILE()
// nTypePicture
#define BT_FILEFORMAT_BMP 0
#define BT_FILEFORMAT_JPG 1
#define BT_FILEFORMAT_GIF 2
#define BT_FILEFORMAT_TIF 3
#define BT_FILEFORMAT_PNG 4
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
mustafa
Posts: 1069
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Has thanked: 9 times
Been thanked: 274 times
Contact:

Post by mustafa »

Hola GERARDO:
Mira si te sirve este Sample ?

Saludos/Regards/Salam
Mustafa
Attachments
QRCode_New.zip
(592.22 KiB) Downloaded 36 times
QRCode2.jpg
QRCode2.jpg (118.04 KiB) Viewed 514 times

gdp
Posts: 36
Joined: Mon Jan 21, 2013 12:57 am
Has thanked: 1 time

Post by gdp »

Hola,

Muchas gracias a todos, porque me fueron indicando mis errores, y posibles soluciones.
Ya lo pude resolver, , leyendo los datos desde una DBF, genero un QR, que despues lo puedo imprimir y sale bien.
Adjunto el fuente,
Generado en HMG 3.5

Code: Select all

#include "hmg.ch"

Function Main

Private cBaseURL, cCuit, cPtoVta, cTipoCmp, cJSON, cBase64JSON
PRIVATE aBarColor := { 0, 0, 0 }
PRIVATE aBackColor := { 255, 255, 255 }
Private var2
PRIVATE hBitmap := 0 

Sele 1 
USE c:\trash\qr

	cBaseURL    := 'https://www.afip.gob.ar/fe/qr/?p='
	cFecha      := LEFT(dtoc(Fecha),4) + '-' + SUBSTR(dtoc(Fecha),5,2) + '-' + RIGHT(dtoc(Fecha),2)
	cCuit       := ALLTRIM(STR(CUITE))
	cPtoVta     := ALLTRIM( STR(NPDV) )
	cTipoCmp    := ALLTRIM(STR(TipoDoc)) 
	cNroCmp     := ALLTRIM( STR(NroComp) )
	cImporte    := ALLTRIM( STR(Importe) )
	cMoneda     := ALLTRIM(Mon)
	cCtz        := ALLTRIM(STR(Cot))
	cTipoDocRec := ALLTRIM( STR(TipoDocR) )
	cNroDocRec  := ALLTRIM( STR(NroDocR) )
	cCodAut		:= ALLTRIM( STR(NCAEA) )

	
	* Crear Texto QR

	cJSON := '{"ver":1,"fecha":"' + cFecha + '","cuit":' + cCuit + ',"ptoVta":' + cPtoVta + ',"tipoCmp":' + cTipoCmp + ',"nroCmp":' + cNroCmp + ',"importe":' + cImporte + ',"moneda":"' + cMoneda + '","ctz":' + cCtz + ',"tipoDocRec":' + cTipoDocRec + ',"nroDocRec":' + cNroDocRec + ',"tipoCodAut":"E","codAut":' + cCodAut + '}'
	cBase64JSON := hb_base64encode( cJSON )
	cFullCode := cBaseURL + cBase64JSON
	
	CreateBarCode()

  
Return	
	
function CreateBarCode
   local hBitMap
   
   hBitMap := HMG_CreateBarCode( cFullCode,;
                   "QRCODE",;
                   12,;
                   12,;
                   .t.,;
                   ,;
                   aBarColor,;
                   aBackColor,;
                   .t.,;  // checksum
                   .f.,;  // wide2_5
                   .f. )  // wide3    	
                   
   Ret:= BT_BitmapSaveFile (hBitmap, "QR.jpg", BT_FILEFORMAT_JPG)
                   
                  
Return               

Muchas gracias a todos,

GERARDO

Post Reply