이 간단한 방법 예시는 **C++에서 QR code를 생성하는 방법에 대한 것입니다. QR 코드는 2차원 바코드의 한 유형이며 C++ 개발자가 다른 응용 프로그램에서 매우 일반적으로 사용합니다. C++ QR 코드 생성기에서 애플리케이션은 타사 API 또는 도구에 의존하지 않고 몇 단계와 매우 간단한 API 호출로 개발할 수 있습니다. 개발된 응용 프로그램은 MS Windows 환경 내의 모든 C++ 기반 응용 프로그램에서 사용할 수 있습니다.
C++에서 QR 코드를 생성하는 단계
- 애플리케이션에서 NuGet 패키지 관리자 도구를 사용하여 Aspose.Barcode for C++ 추가
- Aspose::Barcode 및 AsposeBarCode::Generation 네임스페이스에 대한 참조 추가
- 애플리케이션에 필수 헤더 파일 참조 포함
- 인코딩 유형으로 QR을 설정하여 QR 코드를 생성하도록 BarcodeGenerator 클래스 객체를 초기화합니다.
- QR 코드 텍스트 및 기타 매개변수 설정
- C++에서 저장 방법을 사용하여 PNG 이미지 형식의 QR 코드 생성
QR 코드 생성기를 개발하기 위해 위 단계에서 지정된 C++ 코드를 사용할 수 있습니다. NuGet을 사용하여 API 패키지를 설치하고 필요한 헤더 파일을 애플리케이션에 포함시킨 후 BarcodeGenerator 클래스의 인스턴스로 프로세스를 시작하고 인코딩 유형을 QR로 설정합니다. 다른 EncodingTypes를 사용할 수 있지만 이 예에서는 QR 코드에 중점을 둡니다. 그런 다음 QR 코드 텍스트 및 QR 코드의 해상도와 같은 기타 중요한 매개변수를 설정합니다. 마지막으로 저장 방법을 사용하여 QR 코드가 디스크에 저장됩니다.
C++에서 QR 코드를 생성하는 예
#pragma once | |
#include <system/string.h> | |
#include <system/shared_ptr.h> | |
#include <stdio.h> | |
#include <system/console.h> | |
#include <system/environment.h> | |
#include <system/object_ext.h> | |
#include <Licensing/License.h> | |
#include <BarCode.Generation/BarcodeGenerator.h> | |
#include <BarCode.Generation/EncodeTypes/EncodeTypes.h> | |
#include <BarCode.Generation/EncodeTypes/SymbologyEncodeType.h> | |
#include <BarCode.Generation/EncodeTypes/BarcodeClassifications.h> | |
#include <BarCode.Generation/EncodeTypes/BaseEncodeType.h> | |
#include <BarCode.Generation/GenerationParameters/BarCodeImageFormat.h> | |
#include <BarCode.Generation/GenerationParameters/BarcodeParameters.h> | |
#include <BarCode.Generation/GenerationParameters/BaseGenerationParameters.h> | |
#include <BarCode.Generation/Helpers/Unit.h> | |
using namespace System; | |
using namespace Aspose::BarCode; | |
using namespace Aspose::BarCode::Generation; | |
class QRCodeGenerator { | |
public: | |
static void GenerateQRCode() | |
{ | |
// Set the license for Aspose.BarCode for C++ to create QR Code | |
SharedPtr<License> CreateBarcodeLicense = System::MakeObject<License>(); | |
CreateBarcodeLicense->SetLicense(u"Aspose.Barcode.NET.lic"); | |
// Initialize Barcode generator for QR code type | |
System::SharedPtr<BarcodeGenerator> QRGenerator = System::MakeObject<BarcodeGenerator>(EncodeTypes::QR); | |
// Setting QR Code Text | |
QRGenerator->set_CodeText(u"Text To Encode"); | |
// Setting QR code dimension and resolution | |
QRGenerator->get_Parameters()->get_Barcode()->get_XDimension()->set_Millimeters(1.0f); | |
QRGenerator->get_Parameters()->set_Resolution(300); | |
// Save the QR code as PNG image on disk | |
QRGenerator->Save(u"barcode-codetext_out.png", BarCodeImageFormat::Png); | |
} | |
}; |
위의 코드 예제에서는 QR 코드를 생성하기 위해 C++ API 호출이 사용되었음을 확인했습니다. PNG, Tiff, JPEG 또는 BMP 형식과 같은 다양한 출력 이미지 형식의 QR 코드를 얻을 수 있습니다. 또한 간단한 C++ 코드를 사용하여 해상도, 배경색 및 QR 코드 이미지 너비와 높이를 사용자 지정할 수 있습니다.
이 주제에서 우리는 QR 코드 생성기 C++ 기반 API를 개발하기 위해 매우 간단한 API 인터페이스와 단계를 제공하는 것을 목격했습니다. 생성된 QR 코드 이미지를 DOCX에 추가하여 애플리케이션을 더욱 향상시키려면 C++를 사용하여 DOCX에 이미지 추가 방법에 대한 문서를 참조하세요.