How to superimpose the Aspose barcode(of any type like png, jpeg, gif etc) over a PNG image using Aspose Barcode C++ lib on Windows

Dear Aspose Barcode team,

I have a requirement to superimpose a barcode( generated using the Aspose Barcode C++ library ) over a PNG label( which contains multiple information text fields and there is a provision for barcode ).

Could you please provide us a sample code to implement my requirement on Windows platform.

Thanks and Regards
Kalyan

@kalyanpkalyan,
Aspose.BarCode for C++ does not provide superimposing images over other images. You may please try some third party tool for this requirement like I googled and found the following:

Thanks @ahsaniqbalsidiqui for your quick help.

I wanted to explain my requirement to you to discuss more on how to implement it.

Could you please provide me the details like the best time to discuss, skype id/jabber id/MS Teams id to explain my requirement…

Waiting for your reply.

Thanks and Regards
Kalyan

@kalyanpkalyan,
I am afraid that as per policy here at Aspose, we cannot contact users directly on medias mentioned above. You may please share the details on the forum along with images/video, input/output files and expected output generated by some third part tool for our reference. If possible share your sample code also for reproducing the scenario here. This forum may not allow you to attach large files, in this case upload your files to some public file sharing server and share the download link here for us. We will analyze the information and provide assistance accordingly.

As quick advice, you can create barcode image without any captions and draw it as image on other image.

On the Windows platform, the best solution is using GDI+ library which is native from Windows XP.

@ahsaniqbalsidiqui,

I am giving the C++ method which needs to be replaced by Aspose BarCode C++ Lib API calls:

// OverlayBarCode() method creates the BarCode and Overlays/Superimposes it onto HDC hdc (which is a device context)
// ‘hdc’ is holding the background image(which is a Windows Metafile Format) without barcode drawings(images)
int OverlayBarCode( HDC hdc, float nZoomX, float nZoomY )
{
t_BarCode* pBC;
ERRCODE err = BCAlloc( &pBC );

if( err == S_OK )
	err = BCSetBCType( pBC, eBC_3OF9 );

if( err == S_OK )
	err = BCSetModWidth( pBC, "2000" );

BCSetPrintText(pBC, false, false);

BCSetRotation(pBC, deg0);

string message("ABC1234567890XYZ");
if( err == S_OK )
	err = BCSetText( pBC, message.c_str(), message.length() );

if( err == S_OK )
	err = BCCheck( pBC );

if( err == S_OK )
	err = BCCreate( pBC );

if( err == S_OK )
{
	double width = 0.0;
	double height = 0.0;
	int iModuleWidth = 2000;
	RECT rect = { 0, 0, iModuleWidth, 2.0 * 3 };
	err = BCGetBarcodeSize( pBC, &rect, hdc, eMUPixel, &width, &height );

	if( err == S_OK )
	{
		float nFactor = 106.0f / GetDeviceCaps( hdc, LOGPIXELSX );
		rect.left = static_cast<long>( nZoomX * nFactor );
		rect.top = static_cast<long>( nZoomY * nFactor );
		rect.right = rect.left + static_cast<long>( width );
		rect.bottom = rect.top + static_cast<long>( height );

		// This draw generates the BarCode onto the 'rect' coordinates which were set above
		err = BCDraw( pBC, hdc, &rect );
	}
}

BCFree( pBC );

return true;

}

@ahsaniqbalsidiqui, please provide me a similar kind of implementation using Aspose C++ BarCode Lib APIs.
I am in the urgency of getting this done, as I need to finalize the licensing proposal.
Could you please help in getting this done.

***I am attaching the image which needs to be generated
***The image contains a background image with some text items, boxes, lines
***Finally the generated BarCode will be placed over the Background image

SampleImage.png (70.6 KB)

Thanks and Regards
Kalyan

@kalyanpkalyan,
As we have guided you above that super imposing is out of scope for Aspose.Barcode for C++ API. However, you can refer to the links we have shared already. In case you face any issue with Barcode or QR generation then please elaborate. We will provide our feedback after analysis of the issue related to generation of codes.

@ ahsaniqbalsidiqui,

  1. I was trying to save barcode png into ‘Memory Stream’, but compiler is giving an error.

  2. barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding()->get_Top()->set_Millimeters(2.f); ==> these settings also giving compilation error

I am giving the sample below:

#include
#include <system/aspose_cpp_library.h>
#include <system/exception.h>
#include <system/io/path.h>
#include <Licensing/License.h>

#include
#include <system/string.h>
#include <system/shared_ptr.h>
#include <system/object.h>
#include <system/environment.h>
#include <system/console.h>
#include <Generation/EncodeTypes/SymbologyEncodeType.h>
#include <Generation/EncodeTypes/EncodeTypes.h>
#include <Generation/BarCodeImageFormat.h>
#include <BarCode.Generation/BarcodeGenerator.h>
#include <BarCode.Generation/GenerationParameters/BaseGenerationParameters.h>
#include <BarCode.Generation/GenerationParameters/BarcodeParameters.h>
#include <BarCode.Generation/Helpers/Unit.h>
#include <BarCode.Generation/GenerationParameters/CodetextParameters.h>
#include <Generation/CodaBarSymbol.h>
#include <BarCodeRecognition/Recognition/RecognitionSession/BarCodeReader.h>
#include <BarCodeRecognition/Recognition/RecognitionSession/DecodeTypes/DecodeType.h>
#include <system/io/memory_stream.h>

void GenerateCode128()
{
std::cout << “GenerateCode128(): Started\n”;

//--------------------------------------------------------------------------------------//
const System::String codeText = u"ABCTZCS1234567890T4444T5678901234XYZ";

System::SharedPtr<Aspose::BarCode::Generation::BarcodeGenerator> barcodeGenerator = System::MakeObject<Aspose::BarCode::Generation::BarcodeGenerator>(Aspose::BarCode::Generation::EncodeTypes::Code128, codeText);

barcodeGenerator->get_Parameters()->get_Barcode()->get_CodeTextParameters()->set_Location(Aspose::BarCode::Generation::CodeLocation::None);
barcodeGenerator->get_Parameters()->set_RotationAngle(0);

barcodeGenerator->Save(u"Code128__Rot0.jpeg");

//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
// Create a memory stream object that would store barcode image in binary form

//System::SharedPtr<System::IO::Stream> ms = System::MakeObject<System::IO::MemoryStream>();
//System::SmartPtr<System::IO::Stream> ms = System::MakeObject<System::IO::MemoryStream>(System::SmartPtrMode::Shared);
//System::SmartPtr<System::IO::MemoryStream> ms = System::MakeObject<System::IO::MemoryStream>(System::SmartPtrMode::Shared);
//System::SharedPtr<System::IO::MemoryStream> ms = System::MakeObject<System::IO::MemoryStream>();
//System::SmartPtr<System::IO::MemoryStream> ms = System::MakeObject<System::IO::MemoryStream>(nullptr, System::SmartPtrMode::Shared);
//System::SharedPtr<System::IO::Stream> ms = ms1;

System::SharedPtr<System::IO::Stream> ms = System::MakeObject<System::IO::MemoryStream>();

// Call save method of BarCodeImage to store ‘Png’ barcode image to ‘memory stream’
barcodeGenerator->Save(ms, Aspose::BarCode::BarCodeImageFormat::Png);

ms->set_Position(0);

System::SharedPtr<Aspose::BarCode::BarCodeRecognition::BarCodeReader> reader = System::MakeObject<Aspose::BarCode::BarCodeRecognition::BarCodeReader>(ms, Aspose::BarCode::BarCodeRecognition::DecodeType::Code128);

if(reader->Read())
    System::Console::WriteLine(u"\nBarcode from stream recognized as " + reader->GetCodeText() + u"\n\n");
else
    System::Console::WriteLine(u"Barcode from stream failed to recognize\n\n");

//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding()->get_Top()->set_Millimeters(2.f);
barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding()->get_Left()->set_Millimeters(2.f);
barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding()->get_Right()->set_Millimeters(2.f);
barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding()->get_Bottom()->set_Millimeters(2.f);
barcodeGenerator->get_Parameters()->get_Border()->get_Width()->set_Millimeters(0.5f);
barcodeGenerator->get_Parameters()->get_Border()->set_Visible(true);
//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
barcodeGenerator->get_Parameters()->get_Barcode()->get_BarHeight()->set_Millimeters(11);
barcodeGenerator->Save(u"Code39__BarHeight__11mm.png");

barcodeGenerator->get_Parameters()->get_Barcode()->get_BarCodeHeight()->set_Millimeters(4);
barcodeGenerator->Save(u"Code39__BarCodeHeight__4mm.png");

//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
// Set the wide to narrow ratio for the barcode //

barcodeGenerator->get_Parameters()->get_Barcode()->set_WideNarrowRatio(9.0f);
barcodeGenerator->Save(u"Code39__WideNarrowRatio__9.png");

//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
// Set the symbology and code text and X dimension reduction property of barcode and save barcode Image //

System::SharedPtr<Aspose::BarCode::Generation::BarcodeGenerator> barcodeGenerator1 = [&] { auto tmp_0 = System::MakeObject<Aspose::BarCode::Generation::BarcodeGenerator>(Aspose::BarCode::Generation::EncodeTypes::Code128, u"blackReduction"); tmp_0->get_Parameters()->get_Barcode()->get_XDimension()->set_Millimeters(1.2f); return tmp_0; }();

barcodeGenerator1->Save(u"SetWideNarrowRatio__Code128.png");

//--------------------------------------------------------------------------------------//

//--------------------------------------------------------------------------------------//
// Create instance of BarcodeGenerator, specify codetext and symbology in the constructor //

System::SharedPtr<Aspose::BarCode::Generation::BarcodeGenerator> barcodeGenerator2 = [&] { auto tmp_0 = System::MakeObject<Aspose::BarCode::Generation::BarcodeGenerator>(Aspose::BarCode::Generation::EncodeTypes::Codabar, u"11112222333344"); tmp_0->get_Parameters()->get_Barcode()->get_Codabar()->set_CodabarStartSymbol(Aspose::BarCode::CodabarSymbol::A); tmp_0->get_Parameters()->get_Barcode()->get_Codabar()->set_CodabarStopSymbol(Aspose::BarCode::CodabarSymbol::D); return tmp_0; }();

barcodeGenerator2->Save(u"Coabar-start-stop-symbols.png");

//--------------------------------------------------------------------------------------//

std::cout << "GenerateCode128(): Ended\n\n";

}

int main()
{
//const System::String licenseFile = u"Aspose.BarCode.lic";
//System::SharedPtrAspose::BarCode::License license = new Aspose::BarCode::License();
//license->SetLicense(licenseFile);

GenerateCode128();

}

***Please help me in get rid of those compilation errors

Thanks and Regards
Kalyan

@kalyanpkalyan,
We have observed the compilation errors and logged in our database for further investigation. We will write back here once any update is ready to share.

This issue is logged as:
BARCODECPP-424-Compiler errors while saving to MemoryStream and calling barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding() members

@ahsaniqbalsidiqui,

Thanks a lot for your quick response !!

I have another query:

How to convert a generated Aspose C++ Barcode into WMF(Windows Metafile)/EMF format ?
(if possible within the memory stream, without saving it onto the local hard disk)

Could you please let us know how long will it take to get the compiled version of Memory Stream issue ?
(BARCODECPP-424-Compiler errors while saving to MemoryStream and calling barcodeGenerator->get_Parameters()->get_Barcode()->get_Padding() members)

Once we get clarity on the above-mentioned issues, we have to take the decision to proceed further.
At this point, we have a limited time frame.

Waiting for your reply.

Thanks and Regards
Kalyan

@kalyanpkalyan,
get_Paddding() compilation error issue is logged too recently and is not analyzed yet. Please spare us time to analyze it and share our feedback. For the previous issue of saving EMF file, we are gathering information and will share our comments at the earliest.

@ahsaniqbalsidiqui,
It would be great help if you can get us some update on this.
Because we are completely stuck at this point and unable to proceed further to integrate the Aspose Barcode library.

@kalyanpkalyan,
Aspose.BarCode for C++ cannot save EMF file and there is no future plan to support this feature. Regarding the compilation error issue, it is not resolved yet and ETA is also not possible to share right now. We are trying to gather information and will write back here immediately once any update is available for sharing.

We are sorry for the inconvenience caused to you in this regard.

@ahsaniqbalsidiqui,
Thanks for your quick response !!
I would really appreciate if you get me an update on the Memory Stream compilation error at the earliest.

Thanks and Regards
Kalyan

@ahsaniqbalsidiqui ,
Could you please get me an update on the Memory Stream and get_Padding() compilation errors.

Thanks and Regards
Kalyan

@kalyanpkalyan,
You may please spare us little time as this issue is planned to be analyzed in the next week. We will update you here once the analysis is done and some ETA is available for sharing.

@ahsaniqbalsidiqui,
Any update on this?

Thanks and Regards
Kalyan

@kalyanpkalyan,
We have planned this issue to be analyzed this week. You will be notified once any update is available in this regard.

@ahsaniqbalsidiqui
Did you get any update on this issue?

Thanks and Regards
Kalyan

@kalyanpkalyan,
No update is available yet however, we are trying our best to provide some ETA after the complete analysis. We are sorry for the inconvenience caused to you.