1. Devin Martin
  2. FlipSideOut.Linqpad

Commits

Devin Martin  committed c1a7737

convert qr to zxing

  • Participants
  • Parent commits b4568c6
  • Branches master

Comments (0)

Files changed (3)

File FlipSideOut.Linqpad/DisplayExtensions.cs

View file
 using System;
 using System.Drawing;
+using System.Drawing.Imaging;
 using System.IO;
 using System.Net;
 using System.Web;
+using ZXing;
+using ZXing.Common;
 
 namespace FlipSideOut.Linqpad
 {
     public static class DisplayExtensions
     {
 
-        public static Bitmap ToQrCode(this string data)
+        public static Bitmap ToQrCode(this string data, int height = 250, int width = 250, int margin = 0)
         {
-            var url = string.Format("http://qrcode.kaywa.com/img.php?s=4&d={0}", HttpUtility.UrlEncode(data));
-            using (var web = new WebClient())
+            var barcodeWriter = new BarcodeWriter
             {
-                var imageData = web.DownloadData(url);
-                using (var stream = new MemoryStream(imageData))
+                Format = BarcodeFormat.QR_CODE,
+                Options = new EncodingOptions
                 {
-                    return new Bitmap(stream);
+                    Height = height,
+                    Width = width,
+                    Margin = margin
                 }
-            }
+            };
+
+            return barcodeWriter.Write(data);
         }
 
         public static Bitmap ToQrCode(this Uri data)

File FlipSideOut.Linqpad/FlipSideOut.Linqpad.csproj

View file
     <Reference Include="System.Web" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Windows.Forms.DataVisualization" />
+    <Reference Include="zxing">
+      <HintPath>..\packages\ZXing.Net.0.14.0.1\lib\net40\zxing.dll</HintPath>
+    </Reference>
+    <Reference Include="zxing.presentation">
+      <HintPath>..\packages\ZXing.Net.0.14.0.1\lib\net40\zxing.presentation.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ConversionExtensions.cs" />
     <None Include="FlipSideOut.Linqpad.nuspec" />
     <None Include="linqpad-samples\Functional\Memoize.linq" />
     <None Include="linqpad-samples\Histograms\NonUniformDistributionHistograms.linq" />
+    <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

File FlipSideOut.Linqpad/packages.config

View file
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="ZXing.Net" version="0.14.0.1" targetFramework="net45" />
+</packages>