Recent

Author Topic: [Solved] [Verified] GPS to QR code (WMF stream)  (Read 3157 times)

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
[Solved] [Verified] GPS to QR code (WMF stream)
« on: August 04, 2020, 05:17:49 pm »
Hi,  :D

I'm trying to create a 32bit windows DLL, which:

    - gets a GPS coordinate as input, and
    - adds back a WMF image-stream including a generated QR code of that GPS.

For that, my guess is to use 2 componenst:
Barcodes , FpVectorial
But how do I convert the generated QR code into a WMF stream ?

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     QQ: TBarcodeQR;  
  3. ...
  4.   QQ.Text:= 'geo:47.629521,19.211276';  
  5.   QQ.Generate();
  6.    // ???
  7.  

Thanks for any help!
« Last Edit: August 06, 2020, 05:11:54 am by PizzaProgram »
x86_64-win64 --Win7 PRO 64bit HUN

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: GPS to QR code (WMF stream)
« Reply #1 on: August 04, 2020, 10:53:07 pm »
if you can get the QR code into a image (Bitmap image) then you can use the streaming out canvas.Draw(X,Y, TheImage);

 I don't remember now how the WMF handles but you may want to concentrate on the enhanced version of the format.

 Unless of course  your terminology of WMF is just a general statement of any image format windows can handle?
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: GPS to QR code (WMF stream)
« Reply #2 on: August 04, 2020, 11:20:44 pm »

    - adds back a WMF image-stream including a generated QR code of that GPS.


Hi!

WMF was part of the 16-Bit World of Win 3.1 - back in the 90s.
It was full of errors and you could crash some graphic programms with WMF .
Nobody delivered graphics in the WMF format with the exception of M$.
Even M$ does not care about it anymore.

Leave the deads behind - they wont follow you ( Bob Dylan )

Winni

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: GPS to QR code (WMF stream)
« Reply #3 on: August 05, 2020, 01:00:13 am »
I played a bit with LazBarCodes and noticed that there is a general painting method TLazBarcodeCustomBase.intfPaintOnCanvas. Since it wants to paint to a Canvas, but WMF cannot be accessed by FPVectorial via a canvas, only via an TvVectorialDocument I essentially duplicated this method and replaced the canvas and the related calls by the corresponding vectorial objects and methods. In the end, it was not too difficult.

Please see the attached demo project. You enter the code to be put into the QRCode in the edit and click the button. Then a file "barcode.wmf" will be created. I checked it with my smartphone - the code is readable.

The project requires the package LazBarCodes (install it with Online-Package-Manager if you don't have it). It also requires FPVectorial which comes with the Lazarus installation; but I don't know whether it is accessible by default - if not, open the package file fpvectorialpkg.lpk (in folder components/fpvectorial) and compile it.

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
[Solved] [Verified] Re: GPS to QR code (WMF stream)
« Reply #4 on: August 06, 2020, 05:11:10 am »
 8) Cool !    Works perfectly.
Thank you [wp] very very very much!!! What amazing piece of code!

I've also tried under CodeTyphoon.

First I had an error at fpvectorial.pas > 10105. line, because GvVectorialFormats array was empty.
Had to add wmfvectorialwriter unit to the uses clause, so :
Code: Pascal  [Select][+][-]
  1. initialization
  2.   RegisterVectorialWriter(TvWMFVectorialWriter, vfWindowsMetafileWMF);  

gets called at start.

PS: Sent a msg. about donating...
« Last Edit: August 06, 2020, 05:30:24 am by PizzaProgram »
x86_64-win64 --Win7 PRO 64bit HUN

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #5 on: August 06, 2020, 10:14:03 am »
In the FPVectorial package options, the box "Add package unit to uses section" is checked, which adds unit fpvectorialpkg.pas to the uses clause of the project file and registers all readers/writers. For your case, this is not necessary, therefore, this unit should be removed from the project file, but then wmfvectorialwriter must be added instead in order to register the WMF writer.

In CodeTyphon, this checkmark does not seem to be set, and wmfvectorialwriter must be added explicitly as you noticed.

I put a refactored and more general version to my github LazSamples repo (https://github.com/wp-xyz/LazSamples/tree/master/fpvectorial/BarCodeToVectorial).
« Last Edit: August 06, 2020, 12:13:34 pm by wp »

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: GPS to QR code (WMF stream)
« Reply #6 on: August 06, 2020, 05:43:07 pm »
In the end, it was not too difficult.

One tiny thing I can not figure out myself:
 - How could I remove the big white border of the image? (Crop it, or at least push to Top-Left corner)

My guess is, that TBarcodeQR component is doing it, by "centering" the image, but couldn't find the code for that...  :'(
x86_64-win64 --Win7 PRO 64bit HUN

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #7 on: August 06, 2020, 08:02:27 pm »
Maybe it belongs to the specification because there must be some white space around the QRcode so that the pattern clearly can be distinguished. But I don't know, I am no specialist here, and also I am not the author of LarBarCodes.

As far as I can see in the source code all the painting is done by the zint library, except for some mysterious "X - (X mod BaseX)" and "Y - (Y mod BaseY)" in the code which I duplicated.

Looking at what BaseX and BaseY are, I see that there is a qr^.border_width (the type of qr is defined in the zint libary). For a test I tried to set qr^.border_width to zero, and this moves the QR pattern to the top-left corner of the wmf image. In order to remove the border around the other sides as well I counted the points in the QR pattern: there are 25 dots both horizontally and vertically. So, when you want each dot to be 5 "wmf units" big the size of the QR code must be 25x5 = 125.

The code is rather bull-headed regarding changes in size. I did not investigate further leaving this job to you.

For the attached demo, the project in the previous post was modified to create a "frameless" QRcode.

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #8 on: August 07, 2020, 08:58:49 am »
<OFF>
Perfect!  :D
 You are right, it was right before my nose... looked everywhere except there.
Searched for "margin" instead of "border".

I just ha to comment these 2 parts:
Code: Pascal  [Select][+][-]
  1.  
  2.    BaseX     := qr^.width;// + qr^.border_width*2;
  3.    BaseY     := qr^.rows ;// + qr^.border_width*2;
x86_64-win64 --Win7 PRO 64bit HUN

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #9 on: August 09, 2020, 04:11:40 pm »
Hmmmm... that's strange.

I've pushed the whole code into a DLL.

Since than it stops at the "first line":
Code: Pascal  [Select][+][-]
  1.     barcode := TMyLazBarCode(ABarCode);  

Invalid type cast

PS: I had problems with installation of the necessary components under Lazarus, so I've converted the project to CodeTyphoon, and also had to uninstall Lazarus to not interfear with each other.
Sorry, if it's too much work to "open":

x86_64-win64 --Win7 PRO 64bit HUN

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #10 on: August 09, 2020, 08:05:21 pm »
Sorry I will not put any work into conversion of a CodeTyphon project to Lazarus - go to their forum.

Please specify which problems you had installing the necessary components to Lazarus. Your description is too general to give you specific help.

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #11 on: August 10, 2020, 02:03:36 am »
You are right!  :-[ The least I could do is convert it to Lazarus back myself!

I've installed Lazarus to an other PC (Win7 32bit PRO) >> and the component installation worked nice !  :D
  (So maybe it was a problem interfering with older 1.6 Laz or the CodeTypoon.)

Of course the error is the same, so it's not an "IDE" problem, but the freepascal compiler itself.
Attached the zip, including the 2 projects:
 - the qrIDE is the EXE
 - and 'qpsqrgen.lpr' is the DLL

To test the DLL > you need to re-set the "Running parameter" at the DLL > choose the compiled EXE.
(if I did not set the full path, only the exe-file >> the compiler said: not found...)

Thanks for any help!

Edit2:  (2020-08-11)
 Deleted attachment, because a fixed will be uploaded in following post.
« Last Edit: August 11, 2020, 07:02:20 pm by PizzaProgram »
x86_64-win64 --Win7 PRO 64bit HUN

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #12 on: August 11, 2020, 07:00:19 pm »
Important!   fpvectorialpgk package >> wmfvectorialwriter.pas had a BUG!
 Line 55: definitions must be Int64, not Word !
Code: Pascal  [Select][+][-]
  1.    FLogicalMaxX  : Int64; // Max x coordinate used for scaling
  2.    FLogicalMaxY  : Int64; // Max y coordinate used for scaling

Here is the .pas file with enhanced change log:
 (Somebody with access please overwrite in the LAZ installation!)
x86_64-win64 --Win7 PRO 64bit HUN

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #13 on: August 11, 2020, 07:10:16 pm »
Important!   fpvectorialpgk package >> wmfvectorialwriter.pas had a BUG!
 Line 55: definitions must be Int64, not Word !
Code: Pascal  [Select][+][-]
  1.    FLogicalMaxX  : Int64; // Max x coordinate used for scaling
  2.    FLogicalMaxY  : Int64; // Max y coordinate used for scaling
Why? What is happening when they are Word? Why Int64 and not Integer?

PizzaProgram

  • Jr. Member
  • **
  • Posts: 53
  • ...developing Delphi apps since 25 years.
Re: [Solved] [Verified] GPS to QR code (WMF stream)
« Reply #14 on: August 11, 2020, 07:16:59 pm »
Quote
Why? What is happening when they are Word? Why Int64 and not Integer?

Auto-scale not working if width > 25. Range check error.

vec.Width  := 25;   // inch   >> scaling: 25.6mm × 100 × width >> 26 would be too big for 65K (Word) >> will be scaled back

See: procedure PrepareScaling(...);
 and you'll understand.
Worked the last 16+ hours on this to debug. Now it's working fine.  O:-)
x86_64-win64 --Win7 PRO 64bit HUN

 

TinyPortal © 2005-2018