Browse Source

add support for Png image in Delphi.

Ugochukwu Mmaduekwe 7 years ago
parent
commit
1afd4acc32

+ 2 - 7
QRCodeGenLib.Demo/src/uQrCodeGeneratorDemo.pas

@@ -13,6 +13,7 @@ uses
   Graphics,
 {$IFDEF DELPHI}
   Imaging.jpeg, // for Delphi JPEG Support
+  Imaging.pngimage, // for Delphi PNG Support
 {$ENDIF DELPHI}
   QlpIQrCode,
   QlpQrCode,
@@ -271,9 +272,7 @@ var
   LFilePath: String;
   LBitmap: TBitmap;
   LJpeg: TJPEGImage;
-{$IFDEF FPC}
-  LPng: TPortableNetworkGraphic;
-{$ENDIF FPC}
+  LPng: {$IFDEF FPC}TPortableNetworkGraphic{$ELSE}TPngImage{$ENDIF FPC};
 begin
   LFilePath := ExtractFilePath(ParamStr(0));
   LFilePath := IncludeTrailingPathDelimiter(LFilePath);
@@ -292,17 +291,13 @@ begin
   LBitmap := AQrCode.ToBmpImage(AScale, ABorder);
   // save jpeg
   LJpeg := AQrCode.ToJpegImage(AScale, ABorder);
-{$IFDEF FPC}
   // save png
   LPng := AQrCode.ToPngImage(AScale, ABorder);
-{$ENDIF FPC}
   try
     try
       LBitmap.SaveToFile(LFilePath + '.bmp');
       LJpeg.SaveToFile(LFilePath + '.jpg');
-{$IFDEF FPC}
       LPng.SaveToFile(LFilePath + '.png');
-{$ENDIF FPC}
       AQrCode.ToSvgFile(ABorder, LFilePath + '.svg');
     except
       raise;

+ 4 - 3
QRCodeGenLib/src/Interfaces/QlpIQrCode.pas

@@ -8,6 +8,7 @@ uses
   Graphics,
 {$IFDEF DELPHI}
   Imaging.jpeg, // for Delphi JPEG Support
+  Imaging.pngimage, // for Delphi PNG Support
 {$ENDIF DELPHI}
   QlpQRCodeGenLibTypes;
 
@@ -107,7 +108,6 @@ type
     /// </remarks>
     function ToJpegImage(AScale, ABorder: Int32): TJPEGImage;
 
-{$IFDEF FPC}
     /// <summary>
     /// Returns a png image depicting this QR Code, with the specified
     /// module scale and border modules. For example, ToBmpImage(scale=10,
@@ -134,8 +134,9 @@ type
     /// <b>The caller is responsible for the lifetime of the returned image
     /// object.</b>
     /// </remarks>
-    function ToPngImage(AScale, ABorder: Int32): TPortableNetworkGraphic;
-{$ENDIF FPC}
+    function ToPngImage(AScale, ABorder: Int32):
+{$IFDEF FPC}TPortableNetworkGraphic{$ELSE}TPngImage{$ENDIF FPC};
+
     /// <summary>
     /// Returns a string of SVG code for an image depicting this QR Code,
     /// with the specified number of border modules. The string always uses

+ 7 - 9
QRCodeGenLib/src/QRCodeGen/QlpQrCode.pas

@@ -11,6 +11,7 @@ uses
   Graphics,
 {$IFDEF DELPHI}
   Imaging.jpeg, // for Delphi JPEG Support
+  Imaging.pngimage, // for Delphi PNG Support
 {$ELSE}
   Interfaces, // Added so that Lazarus/FPC will Initialize the WidgetSet
 {$ENDIF DELPHI}
@@ -355,7 +356,6 @@ type
     /// </remarks>
     function ToJpegImage(AScale, ABorder: Int32): TJPEGImage;
 
-{$IFDEF FPC}
     /// <summary>
     /// Returns a png image depicting this QR Code, with the specified
     /// module scale and border modules. For example, ToBmpImage(scale=10,
@@ -382,8 +382,9 @@ type
     /// <b>The caller is responsible for the lifetime of the returned image
     /// object.</b>
     /// </remarks>
-    function ToPngImage(AScale, ABorder: Int32): TPortableNetworkGraphic;
-{$ENDIF FPC}
+    function ToPngImage(AScale, ABorder: Int32):
+{$IFDEF FPC}TPortableNetworkGraphic{$ELSE}TPngImage{$ENDIF FPC};
+
     /// <summary>
     /// Returns a string of SVG code for an image depicting this QR Code,
     /// with the specified number of border modules. The string always uses
@@ -979,14 +980,13 @@ begin
   end;
 end;
 
-{$IFDEF FPC}
-
-function TQrCode.ToPngImage(AScale, ABorder: Int32): TPortableNetworkGraphic;
+function TQrCode.ToPngImage(AScale, ABorder: Int32):
+{$IFDEF FPC}TPortableNetworkGraphic{$ELSE}TPngImage{$ENDIF FPC};
 var
   LBitmap: TBitmap;
 begin
   LBitmap := ToBmpImage(AScale, ABorder);
-  Result := TPortableNetworkGraphic.Create;
+  Result := {$IFDEF FPC}TPortableNetworkGraphic{$ELSE}TPngImage{$ENDIF FPC}.Create;
   try
     Result.Assign(LBitmap);
   finally
@@ -994,8 +994,6 @@ begin
   end;
 end;
 
-{$ENDIF FPC}
-
 function TQrCode.ToSvgString(ABorder: Int32): String;
 var
   LColumn, LRow: Int32;

+ 0 - 1
QRCodeGenLib/src/Utils/QlpQRCodeGenLibTypes.pas

@@ -8,7 +8,6 @@ uses
   SysUtils;
 
 type
-
   EQRCodeGenLibException = class(Exception);
   EInvalidOperationQRCodeGenLibException = class(EQRCodeGenLibException);
   EIndexOutOfRangeQRCodeGenLibException = class(EQRCodeGenLibException);

+ 1 - 1
README.md

@@ -10,7 +10,7 @@ Features
 Core features:
 
 * Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard
-* Output formats: Raw modules/pixels of the QR symbol, SVG XML string/file, `ImageObject`(`bmp`, `jpg` (and `png` for Lazarus/FPC)).
+* Output formats: Raw modules/pixels of the QR symbol, SVG XML string/file, `ImageObject`(`bmp`, `jpg` and `png`).
 * Encodes numeric and special-alphanumeric text in less space than general text
 * Open source code under the permissive MIT License