C# Barcode Read & Write ( ZXing.NET 사용)
바코드 라이브러리로 유명한 ZXing 이라는 것이 있다.
[
zxing/zxing
ZXing ("Zebra Crossing") barcode scanning library for Java, Android - zxing/zxing
github.com
](https://github.com/zxing/zxing)
.NET으로도 제공하는데 이를 따라가다 보면 코드를 그냥 써먹기에는 참조가 많다
그래서 간단하게 쓰는 예제를 찾았는데
[
How to read and create barcode images using C# and ZXing.NET
I’ve written a few posts recently on computer vision and optical character recognition. This time, I thought I’d write about a more traditional way of allowing computers to read printed…
jeremylindsayni.wordpress.com
바코드 이미지를 읽는 방법과 만드는 방법을 간단하게 소개해두었다
우선 비주얼 스튜디오 확장 패키지에서
Install-Package ZXing.Net 으로 라이브러리 설치하고
Read
static void Main(string[] args)
{
// create a barcode reader instance
var barcodeReader = new BarcodeReader();
// create an in memory bitmap
var barcodeBitmap = (Bitmap)Bitmap.FromFile(@"C:\Users\jeremy\Desktop\qrimage.bmp");
// decode the barcode from the in memory bitmap
var barcodeResult = barcodeReader.Decode(barcodeBitmap);
// output results to console
Console.WriteLine($"Decoded barcode text: {barcodeResult?.Text}");
Console.WriteLine($"Barcode format: {barcodeResult?.BarcodeFormat}");
}
Write
static void Main(string[] args)
{
// instantiate a writer object
var barcodeWriter = new BarcodeWriter();
// set the barcode format
barcodeWriter.Format = BarcodeFormat.QR_CODE;
// write text and generate a 2-D barcode as a bitmap
barcodeWriter
.Write("https://jeremylindsayni.wordpress.com/")
.Save(@"C:\Users\jeremy\Desktop\generated.bmp");
}
Write 의 경우 .Save를 추가하지 않으면 bitmap 형식으로 Picturebox 에 할당할 수 있다.