C\#문자열 에 따라 QR 코드 를 만 드 는 인 스 턴 스 코드
2.새 컨트롤 러 및 배경 코드 작성
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZXing;
using ZXing.QrCode;
namespace WebApplication1.Controllers
{
public class StrController : Controller
{
// GET: Str
public ActionResult Index()
{
return View();
}
/// <summary>
///
/// </summary>
/// <param name="text"> </param>
/// <param name="width"> </param>
/// <param name="height"> </param>
/// <returns></returns>
public string QRcode(string text, string width, string height)
{
string Response = "";
try
{
BarcodeWriter writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options.DisableECI = true;
//
options.CharacterSet = "UTF-8";
//
options.Width = Convert.ToInt32(width);
options.Height = Convert.ToInt32(height);
// ,
options.Margin = 1;
writer.Options = options;
Bitmap map = writer.Write(text);
string di = text + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
// ( , )
string path = Path.Combine("C:\\Users\\zhulin\\Desktop", di);
map.Save(path, ImageFormat.Png);
map.Dispose();
Response = " !";
}
catch (Exception)
{
Response = " !";
}
return Response;
}
}
}
3.전단
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link href="~/Scripts/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet" />
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btn").click(function () {
var w = $("#wd").val();
var h = $("#hg").val();
var text = $("#tx").val();
$.ajax({
url: "/Str/QRcode",
data: "text=" + text + "&width=" + w + "&height=" + h,
success: function (e) {
alert(e);
}
});
});
})
</script>
</head>
<body>
<div style="margin-top:20px;margin-left:20px;">
<p> :<input type="text" style="width:60px;height:32px;border:1px solid #66b1ff;margin-left:3px;" id="wd" /><span style="margin-left:10px;"> :</span><input type="text" style="width:60px;height:32px;border:1px solid #66b1ff;margin-left:3px;" id="hg" /></p>
<input type="text" style="width:200px;height:32px;border:1px solid #66b1ff;" id="tx" placeholder=" ..." /><button type="button" class="btn btn-info" id="btn" style="margin-left:5px;margin-top:-1px;height:33px;"> </button>
</div>
</body>
</html>
4.효과:이상 은 C\#문자열 에 따라 QR 코드 를 생 성 하 는 인 스 턴 스 코드 에 대한 상세 한 내용 입 니 다.C\#문자열 에 따라 QR 코드 를 생 성 하 는 자 료 는 다른 관련 글 을 주목 하 십시오!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C#Task를 사용하여 비동기식 작업을 수행하는 방법라인이 완성된 후에 이 라인을 다시 시작할 수 없습니다.반대로 조인(Join)만 결합할 수 있습니다 (프로세스가 현재 라인을 막습니다). 임무는 조합할 수 있는 것이다. 연장을 사용하여 그것들을 한데 연결시키는 것이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.