QRCodeHelper.cs
using System
;
using System
.Collections
.Generic
;
using System
.Drawing
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
using ThoughtWorks
.QRCode
;
using ThoughtWorks
.QRCode
.Codec
;
using ThoughtWorks
.QRCode
.Codec
.Data
;
using System
.IO
;
using System
.Drawing
.Imaging
;
namespace God
.Tools
{
public class QRCodeHelper
{
public async Task
<byte[]> SetQRAsync(string str
)
{
QRCodeEncoder encoder
= new QRCodeEncoder();
encoder
.QRCodeEncodeMode
= ThoughtWorks
.QRCode
.Codec
.QRCodeEncoder
.ENCODE_MODE
.BYTE
;
encoder
.QRCodeScale
= 10;
encoder
.QRCodeVersion
= 0;
encoder
.QRCodeErrorCorrect
= ThoughtWorks
.QRCode
.Codec
.QRCodeEncoder
.ERROR_CORRECTION
.M
;
string qrdata
= str
;
Bitmap bp
= encoder
.Encode(qrdata
.ToString());
using (MemoryStream ms
= new MemoryStream())
{
bp
.Save(ms
, ImageFormat
.Jpeg
);
byte[] bytes
= new byte[ms
.Length
];
ms
.Position
= 0;
await ms
.ReadAsync(bytes
, 0, bytes
.Length
);
return bytes
;
}
}
}
}
public async Task
<Byte
[]> GetQRCodeAsync(string str
)
{
QRCodeHelper qrh
= new QRCodeHelper();
return await qrh
.SetQRAsync(str
);
}
转载请注明原文地址: https://lol.8miu.com/read-858.html