Aggiunta altri formati codici 1D e 2D
This commit is contained in:
+2
-2
@@ -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
|
||||
|
||||
@@ -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
|
||||
/// <returns></returns>
|
||||
public ActionResult QR(string id)
|
||||
{
|
||||
// se vuoto stea,ware...
|
||||
if (id == null || id == "")
|
||||
{
|
||||
id = "www.steamware.net";
|
||||
int hSize = 600;
|
||||
int wSize = 600;
|
||||
BarcodeFormat formato = BarcodeFormat.QR_CODE;
|
||||
return getImage2D(ref id, hSize, wSize, formato);
|
||||
}
|
||||
#if false
|
||||
// se arriva modo json --> deserializzo
|
||||
if (id.IndexOf("{") >= 0)
|
||||
/// <summary>
|
||||
/// Restituisce un DataMatrix code dato valore
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult DataMatrix(string id)
|
||||
{
|
||||
var richiesta = JsonConvert.DeserializeObject<qrRequest>(id);
|
||||
id = richiesta.valore;
|
||||
int hSize = 600;
|
||||
int wSize = 600;
|
||||
BarcodeFormat formato = BarcodeFormat.DATA_MATRIX;
|
||||
return getImage2D(ref id, hSize, wSize, formato);
|
||||
}
|
||||
#endif
|
||||
// url decode...
|
||||
id = HttpUtility.UrlDecode(id);
|
||||
// creo!
|
||||
QrCodeEncodingOptions options = new QrCodeEncodingOptions
|
||||
/// <summary>
|
||||
/// Restituisce un Aztec code dato valore
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Aztec(string id)
|
||||
{
|
||||
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);
|
||||
int hSize = 600;
|
||||
int wSize = 600;
|
||||
BarcodeFormat formato = BarcodeFormat.AZTEC;
|
||||
return getImage2D(ref id, hSize, wSize, formato);
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce un Code39 1D dato valore
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="pureBarcode">mostrare valore SOLO come codice (false --> testo sotto)</param>
|
||||
/// <returns></returns>
|
||||
public ActionResult code39(string id, bool pureBarcode = false)
|
||||
{
|
||||
int hSize = 70;
|
||||
BarcodeFormat formato = BarcodeFormat.CODE_39;
|
||||
return getImage(id, hSize, formato, pureBarcode);
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce un Code128 1D dato valore
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="pureBarcode">mostrare valore SOLO come codice (false --> testo sotto)</param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Code128(string id, bool pureBarcode = false)
|
||||
{
|
||||
int hSize = 70;
|
||||
BarcodeFormat formato = BarcodeFormat.CODE_128;
|
||||
return getImage(id, hSize, formato, pureBarcode);
|
||||
}
|
||||
|
||||
// Return Image
|
||||
MemoryStream ms = new MemoryStream();
|
||||
pixelData.Save(ms, ImageFormat.Png);
|
||||
ms.Position = 0;
|
||||
return new FileStreamResult(ms, "image/png");
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce un QR code dato valore
|
||||
/// </summary>
|
||||
@@ -158,5 +177,83 @@ namespace QR_GEN.Controllers
|
||||
ms.Position = 0;
|
||||
return new FileStreamResult(ms, "image/png");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Genera immagina barcode richeista secondo dimensioni e formato
|
||||
/// </summary>
|
||||
/// <param name="dataStr"></param>
|
||||
/// <param name="hSize">altezza</param>
|
||||
/// <param name="formato">formati 1D di ZXing</param>
|
||||
/// <param name="pureBarcode">indica se SOLO barcode</param>
|
||||
/// <returns></returns>
|
||||
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");
|
||||
}
|
||||
/// <summary>
|
||||
/// Genera immagina barcode richeista secondo dimensioni e formato
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="hSize"></param>
|
||||
/// <param name="wSize"></param>
|
||||
/// <param name="formato"></param>
|
||||
/// <returns></returns>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,6 +206,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Views\Code1D\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
}
|
||||
}
|
||||
<div class="jumbotron">
|
||||
<h1>QR CODE GENERATOR</h1>
|
||||
<p class="lead">Generatore QR code by Steamware</p>
|
||||
<h1>Multi-format CODE GENERATOR</h1>
|
||||
<p class="lead">Generatore Barcode 1D / 2D by Steamware</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<h2>Text</h2>
|
||||
@@ -26,7 +26,30 @@
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-8 text-center">
|
||||
<div class="row p-2">
|
||||
<div class="col">
|
||||
<h4>QR Code</h4>
|
||||
<img src="@Url.Action("QR", new { id = System.Net.WebUtility.UrlEncode(@QrTextBox) })" alt="QRImage" class="img-fluid mx-auto d-block" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<h4>DataMatrix</h4>
|
||||
<img src="@Url.Action("DataMatrix", new { id = System.Net.WebUtility.UrlEncode(@QrTextBox) })" alt="DmtxImage" class="img-fluid mx-auto d-block" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<h4>Aztec</h4>
|
||||
<img src="@Url.Action("Aztec", new { id = System.Net.WebUtility.UrlEncode(@QrTextBox) })" alt="AztecImage" class="img-fluid mx-auto d-block" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row p-2">
|
||||
<div class="col-6">
|
||||
<h4>Code 39</h4>
|
||||
<img src="@Url.Action("Code39", new { id = System.Net.WebUtility.UrlEncode(@QrTextBox) })" alt="Code39Image" class="img-fluid mx-auto d-block" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<h4>Code 128</h4>
|
||||
<img src="@Url.Action("Code128", new { id = System.Net.WebUtility.UrlEncode(@QrTextBox) })" alt="Code128Image" class="img-fluid mx-auto d-block" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user