{"id":772,"date":"2021-09-07T21:31:58","date_gmt":"2021-09-07T13:31:58","guid":{"rendered":"http:\/\/www.wayln.com\/?p=772"},"modified":"2021-09-07T21:31:58","modified_gmt":"2021-09-07T13:31:58","slug":"c-%e7%94%9f%e6%88%90%e4%ba%8c%e7%bb%b4%e7%a0%81-qrcoder","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=772","title":{"rendered":"C# \u751f\u6210\u4e8c\u7ef4\u7801 QRCoder"},"content":{"rendered":"<p>\u6700\u8fd1\u9879\u76ee\u4e0a\u6709\u4e2a\u9700\u6c42\uff0c\u9700\u8981\u5c06\u67d0\u4e2a\u6587\u4ef6\u7684\u4e0b\u8f7d\u5730\u5740\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u5c55\u793a\u5230\u7f51\u9875\u4e0a.<\/p>\n<p>\u76ee\u524d\u7f51\u4e0a\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\u6709\u597d\u51e0\u79cd\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u3010QRCoder\u3011\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u5f0f<\/p>\n<p>\u4e00\u3001\u9996\u5148\u901a\u8fc7VS\u4e2d\u7684\u3010NUGET\u3011\u4e0b\u8f7d\u5e76\u5f15\u7528QRCoder.dll<\/p>\n<p>\u3000\u3000\u4f7f\u7528VS\u6253\u5f00\u9879\u76ee\uff0c\u9879\u76ee->\u53f3\u952e->\u7ba1\u7406Nuget\u7a0b\u5e8f\u5305\uff0c\u7136\u540e\u9009\u62e9\u8054\u673a\uff0c\u5728\u8f93\u5165\u6846\u4e2d\u8f93\u5165QRCoder,\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/>\n  <a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2021\/09\/wp_editor_md_f7ca30c1b2ae5fa7655c6ffb079f35b7.jpg\"><img decoding=\"async\" src=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2021\/09\/wp_editor_md_f7ca30c1b2ae5fa7655c6ffb079f35b7.jpg\" alt=\"\" \/><\/a><br \/>\n  \u4e8c\u3001\u7f16\u5199\u751f\u6210\u4e8c\u7ef4\u7801\u4ee3\u7801\uff0c\u5e76\u8fd4\u56de\u81f3\u9875\u9762<\/p>\n<p>1\u3001WebFrom \uff08\u9879\u76ee\u6846\u67b6\uff09<\/p>\n<p>2\u3001\u529f\u80fd\u573a\u666f\uff1a\u5ba2\u6237\u7aef\u6d4f\u89c8\u5668\u4f7f\u7528jQuery.ajax \u8bf7\u6c42\u670d\u52a1\u7aef\u8fd4\u56de\u4e8c\u7ef4\u7801\uff0c\u670d\u52a1\u7aef\u901a\u8fc7\u4e00\u822c\u5904\u7406\u7a0b\u5e8fHandler.ashx \u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u5e76\u8fd4\u56de\u4e8c\u7ef4\u7801\u81f3\u5ba2\u6237\u7aef<\/p>\n<pre><code class=\"language-CSharp line-numbers\">\/\/ \u751f\u6210\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\nstring strCode = \"http:\/\/www.walys.com\";\nQRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();\nQRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);\nQRCode qrcode = new QRCode(qrCodeData);\n\n\/\/ qrcode.GetGraphic \u65b9\u6cd5\u53ef\u53c2\u8003\u6700\u4e0b\u53d1\u201c\u8865\u5145\u8bf4\u660e\u201d\nBitmap qrCodeImage = qrcode.GetGraphic(5,Color.Black,Color.White,null,15,6,false);\u3000\nMemoryStream ms = new MemoryStream();\nqrCodeImage.Save(ms, ImageFormat.Jpeg);\n\n\/\/ \u5982\u679c\u60f3\u4fdd\u5b58\u56fe\u7247 \u53ef\u4f7f\u7528  qrCodeImage.Save(filePath);\n\n\/\/ \u54cd\u5e94\u7c7b\u578b\ncontext.Response.ContentType = \"image\/Jpeg\";\n\/\/\u8f93\u51fa\u5b57\u7b26\u6d41\ncontext.Response.BinaryWrite(ms.ToArray());\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4e3aQRCoder\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u6838\u5fc3\u4ee3\u7801<\/p>\n<p>\u8865\u5145\u8bf4\u660e\uff1aQRCode.GetGraphic\u65b9\u6cd5\u53c2\u6570\u8bf4\u660e\u3000<\/p>\n<p>Bitmap qrCodeImage = qrcode.GetGraphic(5,Color.Black,Color.White,null,15,6,false);\u3000<\/p>\n<pre><code class=\"language-CSharp line-numbers\">\/* GetGraphic\u65b9\u6cd5\u53c2\u6570\u8bf4\u660e\n                 public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Bitmap icon = null, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true)\n             * \n                 int pixelsPerModule:\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u7247\u7684\u50cf\u7d20\u5927\u5c0f \uff0c\u6211\u8fd9\u91cc\u8bbe\u7f6e\u7684\u662f5 \n             * \n                 Color darkColor\uff1a\u6697\u8272   \u4e00\u822c\u8bbe\u7f6e\u4e3aColor.Black \u9ed1\u8272\n             * \n                 Color lightColor:\u4eae\u8272   \u4e00\u822c\u8bbe\u7f6e\u4e3aColor.White  \u767d\u8272\n             * \n                 Bitmap icon :\u4e8c\u7ef4\u7801 \u6c34\u5370\u56fe\u6807 \u4f8b\u5982\uff1aBitmap icon = new Bitmap(context.Server.MapPath(\"~\/images\/zs.png\")); \u9ed8\u8ba4\u4e3aNULL \uff0c\u52a0\u4e0a\u8fd9\u4e2a\u4e8c\u7ef4\u7801\u4e2d\u95f4\u4f1a\u663e\u793a\u4e00\u4e2a\u56fe\u6807\n             * \n                 int iconSizePercent\uff1a \u6c34\u5370\u56fe\u6807\u7684\u5927\u5c0f\u6bd4\u4f8b \uff0c\u53ef\u6839\u636e\u81ea\u5df1\u7684\u559c\u597d\u8bbe\u7f6e \n             * \n                 int iconBorderWidth\uff1a \u6c34\u5370\u56fe\u6807\u7684\u8fb9\u6846\n             * \n                 bool drawQuietZones:\u9759\u6b62\u533a\uff0c\u4f4d\u4e8e\u4e8c\u7ef4\u7801\u67d0\u4e00\u8fb9\u7684\u7a7a\u767d\u8fb9\u754c,\u7528\u6765\u963b\u6b62\u8bfb\u8005\u83b7\u53d6\u4e0e\u6b63\u5728\u6d4f\u89c8\u7684\u4e8c\u7ef4\u7801\u65e0\u5173\u7684\u4fe1\u606f \u5373\u662f\u5426\u7ed8\u753b\u4e8c\u7ef4\u7801\u7684\u7a7a\u767d\u8fb9\u6846\u533a\u57df \u9ed8\u8ba4\u4e3atrue\n   *\/\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u9879\u76ee\u4e0a\u6709\u4e2a\u9700\u6c42\uff0c\u9700\u8981\u5c06\u67d0\u4e2a\u6587\u4ef6\u7684\u4e0b\u8f7d\u5730\u5740\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u5c55\u793a\u5230\u7f51\u9875\u4e0a. \u76ee\u524d\u7f51\u4e0a\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\u6709\u597d\u51e0\u79cd\uff0c\u672c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-772","post","type-post","status-publish","format-standard","hentry","category-c","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=772"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":773,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions\/773"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}