diff --git a/QR-GEN.sln b/QR-GEN.sln index 91ac64e..8ed2c1e 100644 --- a/QR-GEN.sln +++ b/QR-GEN.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28306.52 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QR-GEN", "QR-GEN\QR-GEN.csproj", "{4B0464BD-88BC-44A4-9750-AFC4259E7400}" EndProject diff --git a/QR-GEN/Controllers/HomeController.cs b/QR-GEN/Controllers/HomeController.cs index c09e9ea..b2ed139 100644 --- a/QR-GEN/Controllers/HomeController.cs +++ b/QR-GEN/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using ZXing; using ZXing.QrCode; using Newtonsoft.Json; using System.Collections.Generic; +using ZXing.Common; namespace QR_GEN.Controllers { @@ -43,42 +44,60 @@ namespace QR_GEN.Controllers /// public ActionResult QR(string id) { - // se vuoto stea,ware... - if (id == null || id == "") - { - id = "www.steamware.net"; - } -#if false - // se arriva modo json --> deserializzo - if (id.IndexOf("{") >= 0) - { - var richiesta = JsonConvert.DeserializeObject(id); - id = richiesta.valore; - } -#endif - // url decode... - id = HttpUtility.UrlDecode(id); - // creo! - QrCodeEncodingOptions options = new QrCodeEncodingOptions - { - DisableECI = true, - CharacterSet = "UTF-8", - Width = 600, - Height = 600, - Margin = 0 - }; - var writer = new BarcodeWriter(); - writer.Format = BarcodeFormat.QR_CODE; - writer.Options = options; - // scrivo bitmap - var pixelData = writer.Write(id); - - // Return Image - MemoryStream ms = new MemoryStream(); - pixelData.Save(ms, ImageFormat.Png); - ms.Position = 0; - return new FileStreamResult(ms, "image/png"); + int hSize = 600; + int wSize = 600; + BarcodeFormat formato = BarcodeFormat.QR_CODE; + return getImage2D(ref id, hSize, wSize, formato); } + /// + /// Restituisce un DataMatrix code dato valore + /// + /// + /// + public ActionResult DataMatrix(string id) + { + int hSize = 600; + int wSize = 600; + BarcodeFormat formato = BarcodeFormat.DATA_MATRIX; + return getImage2D(ref id, hSize, wSize, formato); + } + /// + /// Restituisce un Aztec code dato valore + /// + /// + /// + public ActionResult Aztec(string id) + { + int hSize = 600; + int wSize = 600; + BarcodeFormat formato = BarcodeFormat.AZTEC; + return getImage2D(ref id, hSize, wSize, formato); + } + /// + /// Restituisce un Code39 1D dato valore + /// + /// + /// mostrare valore SOLO come codice (false --> testo sotto) + /// + public ActionResult code39(string id, bool pureBarcode = false) + { + int hSize = 70; + BarcodeFormat formato = BarcodeFormat.CODE_39; + return getImage(id, hSize, formato, pureBarcode); + } + /// + /// Restituisce un Code128 1D dato valore + /// + /// + /// mostrare valore SOLO come codice (false --> testo sotto) + /// + public ActionResult Code128(string id, bool pureBarcode = false) + { + int hSize = 70; + BarcodeFormat formato = BarcodeFormat.CODE_128; + return getImage(id, hSize, formato, pureBarcode); + } + /// /// Restituisce un QR code dato valore /// @@ -158,5 +177,83 @@ namespace QR_GEN.Controllers ms.Position = 0; return new FileStreamResult(ms, "image/png"); } + + + /// + /// Genera immagina barcode richeista secondo dimensioni e formato + /// + /// + /// altezza + /// formati 1D di ZXing + /// indica se SOLO barcode + /// + private static ActionResult getImage(string dataStr, int hSize, BarcodeFormat formato, bool pureBarcode) + { + // se vuoto steamware... + if (dataStr == null || dataStr == "") + { + dataStr = "www.steamware.net"; + } + dataStr = dataStr.ToUpper(); + // url decode... + dataStr = HttpUtility.UrlDecode(dataStr); + // creo! + EncodingOptions options = new EncodingOptions + { + Height = hSize, + Margin = 0, + PureBarcode= pureBarcode + }; + BarcodeWriter writer = new BarcodeWriter(); + writer.Format = formato; + writer.Options = options; + // scrivo bitmap + System.Drawing.Bitmap pixelData = writer.Write(dataStr); + + // Return Image + MemoryStream ms = new MemoryStream(); + pixelData.Save(ms, ImageFormat.Png); + ms.Position = 0; + return new FileStreamResult(ms, "image/png"); + } + /// + /// Genera immagina barcode richeista secondo dimensioni e formato + /// + /// + /// + /// + /// + /// + private static ActionResult getImage2D(ref string id, int hSize, int wSize, BarcodeFormat formato) + { + // se vuoto steamware... + if (id == null || id == "") + { + id = "www.steamware.net"; + } + id = id.ToUpper(); + // url decode... + id = HttpUtility.UrlDecode(id); + // creo! + QrCodeEncodingOptions options = new QrCodeEncodingOptions + { + DisableECI = true, + CharacterSet = "UTF-8", + Width = 600, + Height = 600, + Margin = 0 + }; + BarcodeWriter writer = new BarcodeWriter(); + writer.Format = formato; + writer.Options = options; + // scrivo bitmap + System.Drawing.Bitmap pixelData = writer.Write(id); + + // Return Image + MemoryStream ms = new MemoryStream(); + pixelData.Save(ms, ImageFormat.Png); + ms.Position = 0; + return new FileStreamResult(ms, "image/png"); + } } } \ No newline at end of file diff --git a/QR-GEN/QR-GEN.csproj b/QR-GEN/QR-GEN.csproj index 73017a9..fb3c6fa 100644 --- a/QR-GEN/QR-GEN.csproj +++ b/QR-GEN/QR-GEN.csproj @@ -206,6 +206,7 @@ + diff --git a/QR-GEN/Views/Home/Index.cshtml b/QR-GEN/Views/Home/Index.cshtml index 2c3c03c..4dbc422 100644 --- a/QR-GEN/Views/Home/Index.cshtml +++ b/QR-GEN/Views/Home/Index.cshtml @@ -10,12 +10,12 @@ } }
-

QR CODE GENERATOR

-

Generatore QR code by Steamware

+

Multi-format CODE GENERATOR

+

Generatore Barcode 1D / 2D by Steamware

-
+

Text

@@ -26,7 +26,30 @@
-
- QRImage +
+
+
+

QR Code

+ QRImage +
+
+

DataMatrix

+ DmtxImage +
+
+

Aztec

+ AztecImage +
+
+
+
+

Code 39

+ Code39Image +
+
+

Code 128

+ Code128Image +
+
\ No newline at end of file