Problem resizing barcode image

I’m trying to create a BarCode image and setting its size. Unfortunately, after setting the AutoSize property to false and setting the new size the image is clipped.


I’m using Aspose.BarCode.WPF version 3.9.1.0 (runtime version = 4.0.30319?).

The first image generated looks good. The second image is clipped.
var rawCode = “BCA00001”;         // raw code (an id from another system)
var formattedCode = BCA00001; // formatted code

using (var builder = new BarCodeBuilder(formattedCode, Symbology.Code128))
{
// Set common properties
builder.CaptionAbove = new Caption { Text = String.Empty, Visible = false };
builder.CaptionBelow = new Caption { Text = String.Empty, Visible = false };
builder.Code128CodeSet = Code128CodeSet.Auto;
builder.CodeLocation = CodeLocation.None;
builder.GraphicsUnit = GraphicsUnit.Millimeter;
builder.ImageQuality = ImageQualityMode.AntiAlias;
builder.Margins = new MarginsF(0f, 0f, 0f, 0f);
builder.Resolution = new Resolution(96f, 96f, ResolutionMode.Customized);

<span style="color:#400080;">using</span> (<span style="color:#400080;">var</span> firstImage <span style="color:#2e53d1;">=</span> builder<span style="color:#2e53d1;">.</span><span style="color:darkcyan;">GenerateBarCodeImage</span>())
{
    firstImage<span style="color:#2e53d1;">.</span><span style="color:darkcyan;">Save</span>(<span style="color:darkblue;">String</span><span style="color:#2e53d1;">.</span><span style="color:darkcyan;">Format</span>(<span style="color:#259241;">"C:\\temp\\{0}_firstImage.png"</span>, rawCode));
}

<span style="color:#937a42;">// Set size properties</span>
builder<span style="color:#2e53d1;">.</span><span style="color:purple;">AutoSize</span> <span style="color:#2e53d1;">=</span> <span style="color:#400080;">false</span>;
builder<span style="color:#2e53d1;">.</span><span style="color:purple;">ImageHeight</span> <span style="color:#2e53d1;">=</span> <span style="color:#259241;">10f</span>;
builder<span style="color:#2e53d1;">.</span><span style="color:purple;">ImageWidth</span> <span style="color:#2e53d1;">=</span> <span style="color:#259241;">25f</span>;

<span style="color:#400080;">using</span> (<span style="color:#400080;">var</span> secondImage <span style="color:#2e53d1;">=</span> builder<span style="color:#2e53d1;">.</span><span style="color:darkcyan;">GenerateBarCodeImage</span>())
{
    secondImage<span style="color:#2e53d1;">.</span><span style="color:darkcyan;">Save</span>(<span style="color:darkblue;">String</span><span style="color:#2e53d1;">.</span><span style="color:darkcyan;">Format</span>(<span style="color:#259241;">"C:\\temp\\{0}_secondImage.png"</span>, rawCode));
}

}


Thanks,
Björn Stenberg

Hi Björ,

Thank you for inquiry.

The image is clipped because the generated barcode will not fit into the size mentioned. Could you please try specifying the width at least 80mm?

Hello Saqib,


Unfortunately I (or the customer) needs a barcode image 10x25mm. I don’t see what you mean by saying that it doesn’t fit into the size. Shouldn’t you resize the image to fit?

/Björn

Hi,

If we re-size the image then it will not be recognized due to the size limitations of Code128 and other 1D barcodes. Would it be possible for you to use other symbologies like QR? A QR barcode of this size specification can contain around 10 characters or more data.

string strCodetext = “BCA00001”;
BarCodeBuilder builder = new BarCodeBuilder(strCodetext, Symbology.QR);
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.AutoSize = false;
builder.xDimension = 0.2f;
builder.yDimension = 0.6f;
builder.ImageHeight = 25f;
builder.ImageWidth = 10f;
builder.Save(“test.png”, ImageFormat.Png);

Hello Saqib,


Thanks for the reply. I didn’t know that there were size limitations on Code 128…

I’ll check if the customer can use any other barcode formats such as QR.

Best regards,
Björn Stenberg

Saqib,


A further question. It looks like the customers barcode scanner (Honeywell 3820) can read only standard 1D and GS1 Databar symbologies.

What is the best barcode format to use if we want really small barcodes. Around the size of 27x7 mm. The codes are generated from standard 7-bit ASCII, e.g. “ABC012345”, always 10 characters.

Any ideas would be appreciated.

Bets regards,
Björn

Hi Björn,

I am sorry, as per my knowledge it would not be possible to create a standard 1D barcode within 27x7 mm. I will also confirm this with the development team and inform you shortly.

Would it be possible to increase the size limits to 40 mm (width) x 7 mm (height)? In this case, you also need to set the xDimension to 0.2f. Using these specifications, Code128 will be generated and recognized correctly.

Other solution would be to use a scanner that can read 2D barcodes like QR. 2D barcodes can contain more data in small barcode size.

Hi,

We need the following information for our analysis:

  1. Device type. Printer or Screen? You specified custom in your code.
  2. Will the DPI always be 96x96?

Hello Saqib,


To clarify. Our customer needs to print barcodelabels. They use 2 different printers: OKI C9655 and Brother QL-560. They print barcodes of varying sizes on different printed materials. The smallest being 27x6 mm. The barcode reader they use is Honeywell 3820.

We want to use Code 128.

All barcodes will be uniform length, 10 characters in width. We can probably apply some kind of shortening algorithm if we need to, thereby getting them down in size to 7 or maybe 6 characters in width.

Does this help?

Best regards,
Björn

Hi Björn,

Thanks for the information. We will look into it.

For 6 characters, if you increase the width to 28mm, then the barcode image would be generated fine with 0.2 x dimension and it should also be readable with the scanning device. Below is the code:

string strCodetext = “ABC456”; // 6 characters
BarCodeBuilder builder = new BarCodeBuilder(strCodetext, Symbology.Code128);
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.AutoSize = false;
builder.xDimension = 0.2f;
builder.ImageHeight = 6f;
builder.ImageWidth = 28f;
builder.CodeLocation = CodeLocation.None;