Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例

这个实例在windows、OS X、IOS和Android等平台运行正常。
本文参考这个网站提供的方法:http://zarko-gajic.iz.hr/firemonkey-mobile-android-ios-qr-code-generation-using-delphi-xe-5-delphizxingqrcode/

代码中用到的DelphiZXingQRCode.Pas点这下载

  1 unit Unit3;
  2
  3 interface
  4
  5 uses
  6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
  8   FMX.Controls.Presentation, FMX.Edit, FMX.StdCtrls,DelphiZXingQRCode,
  9   FMX.ListBox,system.math;
 10
 11 type
 12   TForm3 = class(TForm)
 13     Button1: TButton;
 14     edtText: TEdit;
 15     imgQRCode: TImage;
 16     cmbEncoding: TComboBox;
 17     edtQuietZone: TEdit;
 18     procedure Button1Click(Sender: TObject);
 19   private
 20     { Private declarations }
 21     BMP: TBitmap;
 22   public
 23     { Public declarations }
 24   end;
 25
 26 var
 27   Form3: TForm3;
 28
 29 implementation
 30
 31 {$R *.fmx}
 32
 33 procedure TForm3.Button1Click(Sender: TObject);
 34 const
 35   downsizeQuality: Integer = 2; // bigger value, better quality, slower rendering
 36 var
 37   QRCode: TDelphiZXingQRCode;
 38   Row, Column: Integer;
 39   pixelColor : TAlphaColor;
 40   vBitMapData : TBitmapData;
 41   pixelCount, y, x: Integer;
 42   columnPixel, rowPixel: Integer;
 43   function GetPixelCount(AWidth, AHeight: Single): Integer;
 44   begin
 45     if QRCode.Rows > 0 then
 46       Result := Trunc(Min(AWidth, AHeight)) div QRCode.Rows
 47     else
 48       Result := 0;
 49   end;
 50 begin
 51   QRCode := TDelphiZXingQRCode.Create;
 52   try
 53     QRCode.Data := edtText.Text;
 54     QRCode.Encoding := TQRCodeEncoding(cmbEncoding.ItemIndex);
 55     QRCode.QuietZone := StrToIntDef(edtQuietZone.Text, 4);
 56     pixelCount := GetPixelCount(imgQRCode.Width, imgQRCode.Height);
 57     case imgQRCode.WrapMode of
 58       TImageWrapMode.iwOriginal,TImageWrapMode.iwTile,TImageWrapMode.iwCenter:
 59       begin
 60         if pixelCount > 0 then
 61           imgQRCode.Bitmap.SetSize(QRCode.Columns * pixelCount,
 62             QRCode.Rows * pixelCount);
 63       end;
 64       TImageWrapMode.iwFit:
 65       begin
 66         if pixelCount > 0 then
 67         begin
 68           imgQRCode.Bitmap.SetSize(QRCode.Columns * pixelCount * downsizeQuality,
 69             QRCode.Rows * pixelCount * downsizeQuality);
 70           pixelCount := pixelCount * downsizeQuality;
 71         end;
 72       end;
 73       TImageWrapMode.iwStretch:
 74         raise Exception.Create(‘Not a good idea to stretch the QR Code‘);
 75     end;
 76     if imgQRCode.Bitmap.Canvas.BeginScene then
 77     begin
 78       try
 79         imgQRCode.Bitmap.Canvas.Clear(TAlphaColors.White);
 80         if pixelCount > 0 then
 81         begin
 82           if imgQRCode.Bitmap.Map(TMapAccess.maWrite, vBitMapData)  then
 83           begin
 84             try
 85               for Row := 0 to QRCode.Rows - 1 do
 86               begin
 87                 for Column := 0 to QRCode.Columns - 1 do
 88                 begin
 89                   if (QRCode.IsBlack[Row, Column]) then
 90                     pixelColor := TAlphaColors.Black
 91                   else
 92                     pixelColor := TAlphaColors.White;
 93                   columnPixel := Column * pixelCount;
 94                   rowPixel := Row * pixelCount;
 95                   for x := 0 to pixelCount - 1 do
 96                     for y := 0 to pixelCount - 1 do
 97                       vBitMapData.SetPixel(columnPixel + x,
 98                         rowPixel + y, pixelColor);
 99                 end;
100               end;
101             finally
102               imgQRCode.Bitmap.Unmap(vBitMapData);
103             end;
104           end;
105         end;
106       finally
107         imgQRCode.Bitmap.Canvas.EndScene;
108       end;
109     end;
110   finally
111     QRCode.Free;
112   end;
113 end;
114
115 end.

FMX:

 1 object Form3: TForm3
 2   Left = 0
 3   Top = 0
 4   Caption = ‘Form3‘
 5   ClientHeight = 487
 6   ClientWidth = 328
 7   FormFactor.Width = 320
 8   FormFactor.Height = 480
 9   FormFactor.Devices = [Desktop]
10   DesignerMasterStyle = 3
11   object Button1: TButton
12     Position.X = 32.000000000000000000
13     Position.Y = 104.000000000000000000
14     Size.Width = 89.000000000000000000
15     Size.Height = 44.000000000000000000
16     Size.PlatformDefault = False
17     TabOrder = 0
18     Text = ‘Button1‘
19     OnClick = Button1Click
20   end
21   object edtText: TEdit
22     Touch.InteractiveGestures = [LongTap, DoubleTap]
23     TabOrder = 1
24     Position.X = 32.000000000000000000
25     Position.Y = 56.000000000000000000
26     Size.Width = 233.000000000000000000
27     Size.Height = 32.000000000000000000
28     Size.PlatformDefault = False
29   end
30   object imgQRCode: TImage
31     MultiResBitmap = <
32       item
33       end>
34     Anchors = [akLeft, akTop, akRight, akBottom]
35     MarginWrapMode = Center
36     Position.X = 32.000000000000000000
37     Position.Y = 192.000000000000000000
38     Size.Width = 250.000000000000000000
39     Size.Height = 250.000000000000000000
40     Size.PlatformDefault = False
41   end
42   object cmbEncoding: TComboBox
43     Items.Strings = (
44       ‘Auto‘
45       ‘Numeric‘
46       ‘Alphanumeric‘
47       ‘ISO-8859-1‘
48       ‘UTF-8 without BOM‘
49       ‘UTF-8 with BOM‘)
50     ItemIndex = 0
51     Position.X = 136.000000000000000000
52     Position.Y = 112.000000000000000000
53     Size.Width = 145.000000000000000000
54     Size.Height = 32.000000000000000000
55     Size.PlatformDefault = False
56     TabOrder = 3
57   end
58   object edtQuietZone: TEdit
59     Touch.InteractiveGestures = [LongTap, DoubleTap]
60     TabOrder = 4
61     Text = ‘4‘
62     Position.X = 32.000000000000000000
63     Position.Y = 152.000000000000000000
64     Size.Width = 100.000000000000000000
65     Size.Height = 32.000000000000000000
66     Size.PlatformDefault = False
67   end
68 end

时间: 2024-09-29 03:45:56

Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例的相关文章

Free Lua Scripting Interpreter Library For Delphi XE7 Firemonkey On Android And IOS

http://www.fmxexpress.com/free-lua-scripting-interpreter-library-for-delphi-xe7-firemonkey-on-android-and-ios/ http://blog.spreendigital.de/tag/delphi/ http://blog.spreendigital.de/2015/02/18/verysimple-lua-2-0-a-cross-platform-lua-5-3-0-wrapper-for-

Delphi xe7 up1 调用android振动功能

Delphi xe7 up1 调用android振动功能 振动用到以下4个单元: Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers 使用方法: var LVibrator: JVibrator; begin LVibrator := TJVibrator.Wrap ((SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_S

VS2015 C#利用QrCodeNet生成QR Code

Step by step Create QR Code with QrCodeNet Step.1 新建項目 Step.2 在窗口中拖入一個Button Step.3 下載QrCodeNet代碼,解壓\QrCodeNet\sourceCode\qrcodenet\Gma.QrCodeNet\nuget\lib\net45\Gma.QrCodeNet.Encoding.dll Step.4 加入參考(引用) Step.5 添中using using Gma.QrCodeNet.Encoding;

php和jquery生成QR Code

php生产QR Code 下载qrcode源码,地址:https://sourceforge.net/projects/phpqrcode/files/releases/ 1.解压后引入qrlib.php文件 2.使用 QRcode::png($url); png这个函数的几个参数解释下 png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) $text:二维

Delphi XE7 安装

delphi xe7是一款跨平台的应用程序开发工具,它能快速开发Windows.Mac.iOS.Android和各种电子产品的平台的应用程序, 新版xe7使用了Microsoft Windows图形用户界面的许多先进特性和设计思想,采用了弹性可重复利用的完整的面向对象程序语言(Object-Oriented Language),通过全新的控件和样式使您的Windows应用变得现代化,具有简单.高效.功能强大的特点. 在移动端方面,delphi xe7提供mobile apps的连结功能,可以支援

iOS Workflow 分享 - Create QR Code

上次我分享了一个 Scan QR Code 的 Workflow,这次我分享一个正好相反的.如果我要分享一个 URL(或者是一段非常短的文本)给别人,我就可以用这个 Workflow 来生成 QR Code 图片然后发送给别人. 如果你还没有安装 Workflow,你可以先去免费下载安装上.然后打开 Create QR Code 并点击「GET WORKFLOW」,这个 Workflow 就会被自动导入到你的 Workflow 中去,之后你在分享菜单中就可以调用 Workflow 生成 QR C

Delphi APP 開發入門(二)Android/iOS設定,Hello World

Delphi APP 開發入門(二)Android/iOS設定,Hello World 分享: Share on facebookShare on twitterShare on google_plusone_share 閲讀次數:9047 發表時間:2014/05/12 tags: 行動開發 教學 App Delphi XE6 Android iOS 上一期 讓大家認識Delphi以及安裝後,今天要教大家設定Delphi在Android與iOS的開發環境,並且教大家透過寫出第一個Hello W

[修复] Firemonkey 画线问题(Android &amp; iOS 平台)

问题:官方 QC 的一个 Firemonkey 移动平台画线问题: RSP-14309: [iOS & Android] Delphi 10.1 Berlin - drawing problemshttps://quality.embarcadero.com/browse/RSP-14309 适用:所有 Firemonkey 版本 for Android & iOS 修复方法: 请将源码 FMX.StrokeBuilder.pas 复制到自己的工程目录里,再进行修改. Step1: 找到下

Delphi XE7 GPS控件android下的新变化

Delphi XE7 GPS控件的Android新变化 GPS控件的Accuracy可以起作用了,Accuracy>0时:      1--100:ACCURACY_HIGH  101--500:ACCURACY_MEDIUM  其它值时:ACCURACY_LOW Accuracy=0时根据以下方式进行定位:1.GPS_PROVIDER2.NETWORK_PROVIDER3.PASSIVE_PROVIDER Delphi XE7以前版本GPS控件优先使用网络定位,而XE7是根据Accuracy来