FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby bosibila » Mon Nov 09, 2020 11:45 am

Hello to all members,
I try to create QRcode with function FW_BarCodeBmp() and save it to JPG or PNG file but saved picture has black border around QRcode. Is there any way to disable border?
I modified "\fwh\samples\QRcode.prg" to "QRcode1.prg" to make simple example of my problem. In example I also use "oWnd:SayBarCode()" which works well.

Example #1
Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST FWZEBRA  // Important

function Main()

   local hBmp,cText    
   cText:="https://ancdefg.hij.hr/rn?ilz=7fc0d4da335dedcf569a4e365fc8cf62&datv=20201107_1036&izn=18,90"
   
   hBmp := FW_BarCodeBmp( cText, "QRCODE", 200, 200 )
   FW_SaveImage( hBmp, "name.png" )

return nil


Example #2
Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST FWZEBRA

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

function Main()

   local oWnd, cText, cPrg := cFileSetExt( ExeName(), "prg" )
   //cText    := MEMOREAD( cPrg )
   cText    := "https://ancdefg.hij.hr/rn?ilz=7fc0d4da335dedcf569a4e365fc8cf62&datv=20201107_1036&izn=18,90"

   DEFINE WINDOW oWnd TITLE cPrg FROM 0,0 to 500,200 pixel
   ACTIVATE WINDOW oWnd CENTERED ;
      ON INIT DrawCode(oWnd,cText)
   
return nil

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

function DrawCode(oWnd,cText)

   local oImage, hBmp, hNew

   *
   *   Create QRcode with function FW_BarCodeBmp()
   *
   hBmp := FW_BarCodeBmp( cText, "QRCODE", 500, 500 )
   FW_SaveImage( hBmp, "test1.png" )                                                // save
   @ 37,37 XIMAGE oImage SIZE 110,110 OF oWnd SOURCE "test1.png"                    // draw QRcode at top of window


   *
   *
   *
   oWnd:SayBarCode( cText, { 20,20,-20,-20 }, "QR-CODE" )                           // draw QRcode at center of window

   *
   *   Cut part of image ...
   *
   hNew := FW_TransformBitmap( hBmp, { nil, nil, 0.5, 0.5 }, 1, 0 )                 // cut part of image
   FW_SaveImage( hNew, "test2.png" )                                                // save
   @ 317,37 XIMAGE oImage SIZE 110,110 OF oWnd SOURCE "test2.png"                   // draw QRcode at bottom of window

return nil

Image
Last edited by bosibila on Mon Nov 09, 2020 7:35 pm, edited 2 times in total.
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: FW_BarCodeBmp() / FW_SaveImage() help please ...

Postby Silvio.Falconi » Mon Nov 09, 2020 12:11 pm

try

@ 317,37 XIMAGE oImage SIZE 110,110 OF oWnd SOURCE "test2.png" NOBORDER

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: FW_BarCodeBmp() / FW_SaveImage() help please ...

Postby bosibila » Mon Nov 09, 2020 1:22 pm

Thanks Silvio,
but I may not have described the problem in good way. My problem is not the draw QRcode on screen but the save to PNG/JPG file.
After you compile and start my example you can open with some external picture viewer "test1.png" and "test2.png" and see border on QRcode.
Picture in this topic is only to describe how does it look like in saved files.

Problem is in these two lines:
hBmp := FW_BarCodeBmp( cText, "QRCODE", 500, 500 )
FW_SaveImage( hBmp, "test1.png" )
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby bosibila » Mon Nov 09, 2020 7:38 pm

I found solution from Mr. Nages, works great. Here is working example without black border / background:

Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST FWZEBRA  // Important

function Main()

   local hBmp,cText    
   
   cText:="https://ancdefg.hij.hr/rn?ilz=7fc0d4da335dedcf569a4e365fc8cf62&datv=20201107_1036&izn=18,90"
   
   hBmp := FW_BarCodeBmp( cText, "QRCODE", 200, 200 )
   hBmp := bmp2alpha( hBmp )                                    // without this line QRcode has black frame/background ...
   
   FW_SaveImage( hBmp, "name.png" )

return nil

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

function bmp2alpha( hBmp1 )

   local hBmp, oBmp

   oBmp  := GdiBmp():New()
   oBmp:CreateFromRes( hBmp1, 0 )
   oBmp:Conver24to32Alpha( .f. )
   hBmp  := oBmp:GetGDIHbitmap()
   oBmp:Destroy()
   DeleteObject( hBmp1 )

return hBmp
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby hua » Fri Sep 08, 2023 8:00 am

When I tested with FWH1912, bmp2alpha() is still necessary to avoid getting the frame which would render the qrcode unreadable
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby nageswaragunupudi » Fri Sep 08, 2023 8:53 am

Please try:
Code: Select all  Expand view  RUN
   hBmp := FW_BarCodeBmp( cText, "QRCODE", nWidth, nHeight, nil, .t. )
   FW_SaveImage( hBmp, "qr.png" )
   DeleteObject( hBmp )
   XImage( "qr.png" )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10655
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby hua » Fri Sep 08, 2023 9:14 am

Thanks Rao. That worked!
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby hua » Mon Sep 11, 2023 2:33 am

Just out of curiosity, could the qrcode be generated with white background instead of being transparent?
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby nageswaragunupudi » Mon Sep 11, 2023 3:27 am

Please try
Code: Select all  Expand view  RUN
hBmp := FW_BarCodeBmp( cText, "QRCODE", nWidth, nHeight, nil, CLR_WHITE )

and let us know if this is working well for all purposes.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10655
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby hua » Mon Sep 11, 2023 4:39 am

I got this error
Code: Select all  Expand view  RUN
Application Internal Error - C:\test\TPlusSST\bin\inv.exe
Terminated at: 2023-09-11 12:27:48
Unrecoverable error 9001: Error recovery failure
Called from FW_MAKEYOURBITMAP(2098) in .\source\function\IMGTXTIO.PRG
Called from FW_BARCODEBMP(2071) in .\source\function\IMGTXTIO.PRG
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: FW_BarCodeBmp() / FW_SaveImage() help please [Solved]

Postby nageswaragunupudi » Mon Sep 11, 2023 4:49 am

Yes, sorry.
This does not work in FWH1912.
You need to use later version.
This works in the current version.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10655
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 27 guests