Vous êtes sur la page 1sur 2

Imports QRCoder

Imports System.IO
Imports System.Drawing
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub btnGenerate_Click(sender As Object, e As EventArgs)
Dim code As String = txtCode.Text
Dim qrGenerator As New QRCodeGenerator()
Dim qrCode As QRCodeGenerator.QRCode = qrGenerator.CreateQrCode(code, QR
CodeGenerator.ECCLevel.Q)
Dim imgBarCode As New System.Web.UI.WebControls.Image()
imgBarCode.Height = 150
imgBarCode.Width = 150
Using bitMap As Bitmap = qrCode.GetGraphic(20)
Using ms As New MemoryStream()
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Dim byteImage As Byte() = ms.ToArray()
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase6
4String(byteImage)
End Using
plBarCode.Controls.Add(imgBarCode)
End Using
End Sub
End Class
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Web;
System.Web.UI;
System.Web.UI.WebControls;
QRCoder;
System.IO;
System.Drawing;

public partial class CS : System.Web.UI.Page


{
protected void btnGenerate_Click(object sender, EventArgs e)
{
string code = txtCode.Text;
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGen
erator.ECCLevel.Q);
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebContro
ls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
using (Bitmap bitMap = qrCode.GetGraphic(20))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase6
4String(byteImage);
}
plBarCode.Controls.Add(imgBarCode);
}

}
}
<?xml version="1.0"?>
<!-Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\vx.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!-Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0"/>
<!-The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!-The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm
">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<!-The system.webServer section is required for running ASP.NET AJAX under
Internet
Information Services 7.0. It is not necessary for previous version of I
IS.
-->
</configuration>

Vous aimerez peut-être aussi