Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/281552f8ccf17e6b5ae4e313414184a8 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/281552f8ccf17e6b5ae4e313414184a8 to your computer and use it in GitHub Desktop.
Generate barcodes using C++
System::SharedPtr<BarcodeGenerator> generator = [&] { auto tmp_0 = System::MakeObject<BarcodeGenerator>(EncodeTypes::Code39Standard, System::String(u"1234567890"));
// set caption above
tmp_0->get_Parameters()->get_CaptionAbove()->set_Text(u"Caption Above");
// set visibility
tmp_0->get_Parameters()->get_CaptionAbove()->set_Visible(true);
// set caption below
tmp_0->get_Parameters()->get_CaptionBelow()->set_Text(u"Caption Below");
// set visibility
tmp_0->get_Parameters()->get_CaptionBelow()->set_Visible(true);
// set resolution
tmp_0->get_Parameters()->set_Resolution(300);
return tmp_0; }();
generator->Save(System::String(u"barcode_caption.jpg"));
const System::String codeText = u"1234567";
const System::String fileName = u"code39_barcode.jpg";
// Create barcode generator
System::SharedPtr<BarcodeGenerator> barcodeGenerator = System::MakeObject<BarcodeGenerator>(EncodeTypes::Code39Standard, codeText);
barcodeGenerator->get_Parameters()->set_Resolution(300);
// Generate barcode and save as image
barcodeGenerator->Save(fileName);
System::SharedPtr<BarcodeGenerator> barcodeGenerator = [&] { auto tmp_0 = System::MakeObject<BarcodeGenerator>(EncodeTypes::Aztec, System::String(u"1234567890"));
// set broder style
tmp_0->get_Parameters()->get_Border()->set_DashStyle(Aspose::BarCode::BorderDashStyle::Solid);
// set width
tmp_0->get_Parameters()->get_Border()->get_Width()->set_Millimeters(1.0f);
// set border visibility
tmp_0->get_Parameters()->get_Border()->set_Visible(true);
// set background color
tmp_0->get_Parameters()->set_BackColor(System::Drawing::Color::get_Black());
// set barcode's bar color
tmp_0->get_Parameters()->get_Barcode()->set_ForeColor(System::Drawing::Color::get_Orange());
// set border color
tmp_0->get_Parameters()->get_Border()->set_Color(System::Drawing::Color::get_Black());
// set text color
tmp_0->get_Parameters()->get_Barcode()->get_CodeTextParameters()->set_Color(System::Drawing::Color::get_Orange());
// set image resolution
tmp_0->get_Parameters()->set_Resolution(400);
return tmp_0; }();
barcodeGenerator->Save(System::String(u"custom_barcode.jpg"));
const System::String codeText = u"1234567";
const System::String fileName = u"QR_Code.jpg";
// Create barcode generator
System::SharedPtr<BarcodeGenerator> barcodeGenerator = System::MakeObject<BarcodeGenerator>(EncodeTypes::QR, codeText);
barcodeGenerator->get_Parameters()->set_Resolution(300);
// Generate barcode and save as image
barcodeGenerator->Save(fileName);
// Create instance of BarcodeGenerator class
System::SharedPtr<BarCodeReader> reader = System::MakeObject<BarCodeReader>(u"Code128.png", DecodeType::Code128);
while (reader->Read())
{
// Display code text and Symbology Type
System::Console::WriteLine(System::String(u"CodeText: ") + reader->GetCodeText());
System::Console::Write(System::String(u"Symbology Type: ") + reader->GetCodeType());
}
reader->Close();
// Set barcode symbologies
System::ArrayPtr<System::SharedPtr<BaseDecodeType>> objArray = System::MakeArray<System::SharedPtr<Aspose::BarCode::BarCodeRecognition::BaseDecodeType>>({ DecodeType::Code39Standard, DecodeType::Pdf417 });
// Initialize the BarCodeReader, Call Read() method in a loop and Display the codetext and symbology type
System::SharedPtr<BarCodeReader> reader = System::MakeObject<BarCodeReader>(u"RecognizingMultipleSymbologies.png", objArray);
while (reader->Read())
{
System::Console::WriteLine(System::String(u"Codetext: ") + reader->GetCodeText());
System::Console::WriteLine(System::String(u"Symbology type: ") + reader->GetCodeType());
}
reader->Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment