Hello,
I am using LEADTOOLS V15.0.1.0 and .NET classes
to generate Barcode 2D PDF 417, then embed the image in PDF document using iTextSharp library,but
the image is very large.
I use functions in iTextsharp to scale the barcode
image
problem:
when I open PDF document by Adobe Reader ,It show message that "insufficient image data",
and the image is not appear.
I reduce image size by methods "searching google" but resolution is not good to read barcode by reader.
How can I solve this problem?How can I reduce image size without lose resolution?
Here is My code to generate Barcode Image:
public RasterImage writeBarcode(string barcodedData)
{
Bitmap bmp = new Bitmap(1200, 600);
for (int i = 0; i
{
for (int j = 0; j
{
bmp.SetPixel(i, j, Color.Red);
}
}
RasterImage image = new RasterImage(bmp);
BarcodeEngine barEngine = default(BarcodeEngine);
try
{
RasterSupport.Unlock(RasterSupportType.BarcodesPdfWrite, "MyCode");
BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesPdfWrite);
barEngine = new BarcodeEngine();
BarcodeData data = new BarcodeData();
Rectangle rc = new Rectangle(0, 0, 0, 0);
data.Unit = BarcodeUnit.ScanlinesPerPixels;
data.Location = rc;
data.SearchType = BarcodeSearchTypeFlags.Pdf417;
string[] barcodeText = null;
barcodeText = new string[1];
barcodeText[0] = barcodedData;
Byte[] encodedBytes = System.Text.Encoding.Default.GetBytes(barcodeText[0]);
data.Data = encodedBytes;
BarcodeColor barColor = new BarcodeColor();
barColor.BarColor = Color.Black;
barColor.SpaceColor = Color.White;
BarcodeWritePdf barPDF = new BarcodeWritePdf();
barPDF.AspectHeight = 0;
barPDF.AspectWidth = 0;
barPDF.Columns = 0;
barPDF.Rows = 0;
barPDF.EccLevel = BarcodePdf417EccLevelFlags.Level0;
//barPDF.EccPercentage = 50;
barPDF.Justify = BarcodeJustifyFlags.None;
barPDF.Module = 0;
barPDF.ModAspectRatio = 0;
barEngine.Write(image, data, barColor, BarcodeWriteFlags.InitializationReader, null, barPDF, null, null, Rectangle.Empty);
BarcodeEngine.Shutdown();
}
catch (BarcodeException ex)
{
throw ex;
///if (ex.Code.ToString().Equals("StringLength"))
//MessageBox.Show("Error in length");
}
//get used Width
int w = 0;
for (w = 0; w
{
if ((image.GetPixelColor(0, w).R == 255) && (image.GetPixelColor(0, w).G == 0) && (image.GetPixelColor(0, w).B == 0))
break;
}
int usedWidth = w - 1;
//get used Heigth
int h = 0;
for (h = 0; h
{
if ((image.GetPixelColor(h, 0).R == 255) && (image.GetPixelColor(h, 0).G == 0) && (image.GetPixelColor(h, 0).B == 0))
break;
}
int usedHeight = h - 1;
//copy used Pixels to another Image
Bitmap targetImg = new Bitmap(usedWidth, usedHeight);
RasterImage targetRasterImg = new RasterImage(targetImg);
for (w = 0; w
{
for (h = 0; h
{
targetRasterImg.SetPixelColor(h, w, image.GetPixelColor(h, w));
}
}
return targetRasterImg;
}