using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace G6.MVC.TwoCode.Controllers
{
public class CodeController : Controller
{
// GET: Code
public ActionResult Index()
{
return View();
}
[HttpGet]
public string GetQrCode(string content, int width, int height)
{
Bitmap b = BaseHelper.Generate1(content, width, height);
string strbaser64 = "";
try
{
using (MemoryStream ms = new MemoryStream())
{
b.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
strbaser64 = Convert.ToBase64String(arr);
}
return strbaser64;
}
catch (Exception ex)
{
throw new Exception("转换失败!");
}
}
[HttpGet]
public string GetBarCode(string content, int width, int height)
{
Bitmap b = BaseHelper.Generate2(content, width, height);
string strbaser64 = "";
try
{
using (MemoryStream ms = new MemoryStream())
{
b.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
strbaser64 = Convert.ToBase64String(arr);
}
return strbaser64;
}
catch (Exception ex)
{
throw new Exception("转换失败!");
}
}
}
}