54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Web.Mvc;
|
|
using ZXing;
|
|
using ZXing.QrCode;
|
|
|
|
namespace QR_GEN.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public RedirectResult steamware()
|
|
{
|
|
return Redirect("https://www.steamware.net");
|
|
}
|
|
/// <summary>
|
|
/// Restituisce un QR code dato valore
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public ActionResult QR(string id)
|
|
{
|
|
// se vuoto stea,ware...
|
|
if (id == null || id == "")
|
|
{
|
|
id = "www.steamware.net";
|
|
}
|
|
// 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");
|
|
}
|
|
}
|
|
} |