C\#QrCode.Net 을 이용 하여 QR 코드(Qr 코드)를 만 드 는 방법
QrCode.Net 은 C\#를 사용 하여 QR 코드 그림 을 만 드 는 라 이브 러 리 입 니 다.WinForm,WebForm,WPF,Silverlight,Windows Phone 7 프로그램 에 QR 코드 인 코딩 출력 기능 을 편리 하 게 제공 할 수 있 습 니 다.QR 코드 파일 을 eps 형식 으로 내 보 낼 수 있 습 니 다.
프로젝트 주소:http://qrcodenet.codeplex.com
QrCode.Net 은 더 이상http://code.google.com/p/zxing/ ZXing포트 를 사용 하지 않 습 니 다.새로운 버 전 은 더 좋 은 성능 을 가 질 것 입 니 다.
테스트 결 과 는 다음 과 같 습 니 다(초 단위):
입력 문자열 길이:74 개
EC performance 1000 Tests~ QrCode.Net: 3929 ZXing: 5221
또한,QrCode.Net 은 문자열 을 분석 하여 UTF-8 인 코딩 을 사용 할 지 여 부 를 결정 할 수 있 습 니 다.(예 를 들 어 중국 어 를 사용 할 때.)
QrCode 사용 방법:
새 항목 은 라 이브 러 리 에 대한 인용 을 추가 한 다음 Gma.QrCodeNet.Encoding 네 임 스페이스 를 도입 합 니 다.
using Gma.QrCodeNet.Encoding;
콘 솔 에서 QR 코드 출력:
Console.Write(@"Type some text to QR code: ");
string sampleText = Console.ReadLine();
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
QrCode qrCode = qrEncoder.Encode(sampleText);
for (int j = 0; j < qrCode.Matrix.Width; j++)
{
for (int i = 0; i < qrCode.Matrix.Width; i++)
{
char charToPrint = qrCode.Matrix[i, j] ? '' : ' ';
Console.Write(charToPrint);
}
Console.WriteLine();
}
Console.WriteLine(@"Press any key to quit.");
Console.ReadKey();
이 코드 는 다음 과 같은 출력 을 생 성 합 니 다:Graphics 에 QR 코드 그리 기:
const string helloWorld = "Hello World!";
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = qrEncoder.Encode(helloWorld);
const int moduleSizeInPixels = 5;
Renderer renderer = new Renderer(moduleSizeInPixels, Brushes.Black, Brushes.White);
Panel panel = new Panel();
Point padding = new Point(10,16);
Size qrCodeSize = renderer.Measure(qrCode.Matrix.Width);
panel.AutoSize = false;
panel.Size = qrCodeSize + new Size(2 * padding.X, 2 * padding.Y);
using (Graphics graphics = panel.CreateGraphics())
{
renderer.Draw(graphics, qrCode.Matrix, padding);
}
Writeable Bitmap 에 QR 코드 그리 기:
const string helloWorld = "Hello World!";
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode(helloWorld, out qrCode);
const int moduleSizeInPixels = 5;
Renderer renderer = new Renderer(moduleSizeInPixels); //Black&White is default colour for drawing QrCode
//Matrix under qrCode might be null if input string is null or empty. 21 module wide is version 1 QrCode's width.
int pixelSize = qrCode.Matrix == null ? renderer.Measure(21) : renderer.Measure(qrCode.Matrix.Width);
WriteableBitmap wBitmap = new WriteableBitmap(pixelSize, pixelSize, 96, 96, PixelFormats.Gray8, null);
//If wBitmap is null value. renderer will create Gray8 Bitmap as default.
renderer.Draw(wBitmap, qrCode.Matrix); //Default offset position is (0, 0);
//Now you can put wBitmap to Image control's Source or use it to create image file.
WinForm 이나 WPF 프로그램 에 QR 코드 를 보 여 주 려 면 라 이브 러 리 를 도구 상자 에 끌 어 다 놓 은 다음 창 에서 컨트롤 을 끌 어 낼 수 있 습 니 다.QR 코드 를 파일 에 직접 저장 하기:
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode(helloWorld, out qrCode);
Renderer renderer = new Renderer(5, Brushes.Black, Brushes.White);
renderer.CreateImageFile(qrCode.Matrix, @"c:\temp\HelloWorld.png", ImageFormat.Png);
스 트림 에 QR 코드 쓰기:
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode(helloWorld, out qrCode);
Renderer renderer = new Renderer(5, Brushes.Black, Brushes.White);
MemoryStream ms = new MemoryStream();
renderer.WriteToStream(qrCode.Matrix, ms, ImageFormat.png);
위 에서 말 한 것 은 편집장 님 께 서 소개 해 주신 C\#QrCode.Net 을 사용 하여 QR 코드(Qr 코드)를 생 성 하 는 것 입 니 다.여러분 께 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
각도 바코드 QR 코드 스캔 라이브러리를 만드는 방법다른 Angular 응용 프로그램에서 재사용할 수 있도록 Angular 라이브러리로 전환할 수 있습니다. 이 기사에서는 Angular 바코드 QR 코드 스캐닝 라이브러리를 만드는 과정과 이를 Angular 애플리케이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.