資源簡介
QRCode二維碼維碼支持中文,網上流傳很多版本都說支持中文二維碼。看過測試都有問題,自己看了源碼改了下。
原版本 中有 IsUnicode 方法判斷是否為Unicode編碼 但這個方法好像有問題 所以無法準確判斷中文。可以通過改寫這個來實現中文。
另外有兩個方法 都可以解決中文問題
public virtual String decode(QRCodeImage qrCodeImage, Encoding encoding)
public virtual String decode(QRCodeImage qrCodeImage)
因為是虛方法可以重寫這個方法就可以
所以 可以通過
改寫IsUnicode 和 重寫 這個兩個虛方法來實現
///
/// 用于判斷中文
///
///
///
public static bool IsUnicode(byte[] byteData)
{
// This is by Joson Jiang 用于判斷中文
//因為ascii編碼當中的最大為127,這樣判斷后,
//就能正確的判斷是不是unicode,這樣就能正確的解碼中文了.
bool isUnicode = false;
try
{
foreach (byte value in byteData)
{
if (value > 128)
{
isUnicode = true;
break;
}
}
}
catch (Exception)
{
//其中的是原本的代碼 無法正確判斷 中文
string value1 = FromASCIIByteArray(byteData);
string value2 = FromUnicodeByteArray(byteData);
byte[] ascii = AsciiStringToByteArray(value1);
byte[] unicode = UnicodeStringToByteArray(value2);
if (ascii[0] != unicode[0])
return true;
return false;
}
return isUnicode;//返回是不是Unicode編碼
}
///
/// 重寫直接返回 解決中文問題
///
public class QRCodeDecoders : QRCodeDecoder
{
QRCodeDecoder decoder = new QRCodeDecoder();
public override String decode(QRCodeImage qrCodeImage)
{
sbyte[] data = decoder.decodeBytes(qrCodeImage);
byte[] byteData = new byte[data.Length];
Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length);
String decodedData;
return decodedData =

代碼片段和文件信息
using?System.Reflection;
using?System.Runtime.CompilerServices;
//?General?Information?about?an?assembly?is?controlled?through?the?following
//?set?of?attributes.?Change?these?attribute?values?to?modify?the?information
//?associated?with?an?assembly.
//?TODO:?Review?the?values?of?the?assembly?attributes
[assembly:?Assemblytitle(“ThoughtWorks.QRCode.NET?Component“)]
[assembly:?AssemblyDescription(“A?library?for?QRCode?encoding?and?decoding“)]
[assembly:?AssemblyCompany(““)]
[assembly:?AssemblyProduct(““)]
[assembly:?AssemblyCopyright(““)]
[assembly:?AssemblyTrademark(““)]
[assembly:?AssemblyCulture(““)]
//?Version?information?for?an?assembly?consists?of?the?following?four?values:
//
//??????Major?Version
//??????Minor?Version
//??????Revision
//??????Build?Number
//
//?You?can?specify?all?the?values?or?you?can?default?the?Revision?and?Build?Numbers
//?by?using?the?‘*‘?as?shown?below:
[assembly:?AssemblyVersion(“1.0.*“)]
//
//?In?order?to?sign?your?assembly?you?must?specify?a?key?to?use.?Refer?to?the?
//?Microsoft?.NET?framework?documentation?for?more?information?on?assembly?signing.
//
//?Use?the?attributes?below?to?control?which?key?is?used?for?signing.?
//
//?Notes:?
//???(*)?If?no?key?is?specified?the?assembly?is?not?signed.
//???(*)?KeyName?refers?to?a?key?that?has?been?installed?in?the?Crypto?Service
//???????Provider?(CSP)?on?your?machine.?KeyFile?refers?to?a?file?which?contains
//???????a?key.
//???(*)?If?the?KeyFile?and?the?KeyName?values?are?both?specified?the?
//???????following?processing?occurs:
//???????(1)?If?the?KeyName?can?be?found?in?the?CSP?that?key?is?used.
//???????(2)?If?the?KeyName?does?not?exist?and?the?KeyFile?does?exist?the?key?
//???????????in?the?KeyFile?is?installed?into?the?CSP?and?used.
//???(*)?In?order?to?create?a?KeyFile?you?can?use?the?sn.exe?(Strong?Name)?utility.
//???????When?specifying?the?KeyFile?the?location?of?the?KeyFile?should?be
//???????relative?to?the?project?output?directory?which?is
//???????%Project?Directory%\obj\.?For?example?if?your?KeyFile?is
//???????located?in?the?project?directory?you?would?specify?the?AssemblyKeyFile?
//???????attribute?as?[assembly:?AssemblyKeyFile(“..\..\mykey.snk“)]
//???(*)?Delay?Signing?is?an?advanced?option?-?see?the?Microsoft?.NET?framework
//???????documentation?for?more?information?on?this.
//
[assembly:?AssemblyConfiguration(““)]
[assembly:?AssemblyDelaySign(false)]
[assembly:?AssemblyKeyFile(““)]
[assembly:?AssemblyKeyName(““)]
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3348??2013-01-13?15:38??_UpgradeReport_Files\UpgradeReport.css
?????文件??????12505??2010-05-04?01:19??_UpgradeReport_Files\UpgradeReport.xslt
?????文件?????????69??2013-01-13?15:38??_UpgradeReport_Files\UpgradeReport_Minus.gif
?????文件?????????71??2013-01-13?15:38??_UpgradeReport_Files\UpgradeReport_Plus.gif
?????文件???????2549??2007-06-08?13:38??Backup\QRCodeLib\AssemblyInfo.cs
?????文件????????882??2007-06-30?23:24??Backup\QRCodeLib\data\QRCodeBitmapImage.cs
?????文件????????262??2007-06-30?23:21??Backup\QRCodeLib\data\QRCodeImage.cs
?????文件??????14203??2007-07-30?10:43??Backup\QRCodeLib\data\QRCodeSymbol.cs
?????文件???????4993??2007-07-30?10:43??Backup\QRCodeLib\ecc\BCH15_5.cs
?????文件???????9927??2007-07-30?10:43??Backup\QRCodeLib\ecc\ReedSolomon.cs
?????文件????????399??2007-07-04?22:38??Backup\QRCodeLib\exception\AlignmentPatternNotFoundException.cs
?????文件????????690??2007-07-04?22:38??Backup\QRCodeLib\exception\DecodingFailedException.cs
?????文件????????383??2007-07-04?22:38??Backup\QRCodeLib\exception\FinderPatternNotFoundException.cs
?????文件????????385??2007-07-04?22:38??Backup\QRCodeLib\exception\InvalidDataBlockException.cs
?????文件????????375??2007-07-04?22:38??Backup\QRCodeLib\exception\InvalidVersionException.cs
?????文件????????390??2007-07-04?22:38??Backup\QRCodeLib\exception\InvalidVersionInfoException.cs
?????文件????????381??2007-07-04?22:38??Backup\QRCodeLib\exception\SymbolNotFoundException.cs
?????文件????????160??2007-07-04?22:38??Backup\QRCodeLib\exception\VersionInformationException.cs
?????文件???????1935??2007-06-08?13:38??Backup\QRCodeLib\geom\Axis.cs
?????文件???????3357??2007-06-08?13:38??Backup\QRCodeLib\geom\Line.cs
?????文件???????1507??2007-06-08?13:38??Backup\QRCodeLib\geom\Point.cs
?????文件???????4228??2007-06-08?13:38??Backup\QRCodeLib\geom\SamplingGrid.cs
?????文件??????54356??2007-08-04?21:35??Backup\QRCodeLib\Properties\Resources.Designer.cs
?????文件??????58871??2007-08-04?21:32??Backup\QRCodeLib\Properties\Resources.resx
?????文件??????15507??2007-08-01?15:57??Backup\QRCodeLib\QRCodeDecoder.cs
?????文件??????29736??2007-08-01?21:09??Backup\QRCodeLib\QRCodeEncoder.cs
?????文件??????16634??2007-08-04?21:32??Backup\QRCodeLib\QRCodeLib.csproj
?????文件???????8739??2007-07-30?10:43??Backup\QRCodeLib\reader\pattern\AlignmentPattern.cs
?????文件??????21060??2007-07-30?10:43??Backup\QRCodeLib\reader\pattern\FinderPattern.cs
?????文件???????2550??2007-06-08?13:38??Backup\QRCodeLib\reader\pattern\LogicalSeed.cs
............此處省略754個文件信息
評論
共有 條評論