Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, October 6, 2009 6:20:28 AM(UTC)
Eiadtaha

Groups: Registered
Posts: 7


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;

}
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, October 7, 2009 12:59:27 AM(UTC)
Eiadtaha

Groups: Registered
Posts: 7


Any help please
 
#3 Posted : Wednesday, October 7, 2009 4:59:13 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

I recommend 2 changes to your code:

1. If the image size (width and height) are too large, you can reduce it using Leadtools.ImageProcessing.SizeCommand Class. This class resizes an image to a new width and height.

2. To convert from a LEAD bitmap to a Windows Bitmap, do not copy the data pixel-by-pixel because this is very slow. Instead, use our RasterImage.ConvertToGdiPlusImage method as follows:
Image destImage1 = srcImage.ConvertToGdiPlusImage();

For more information about the SizeCommand Class and ConvertToGdiPlusImage method, please refer to the LEADTOOLS .Net documentation.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#4 Posted : Wednesday, October 7, 2009 6:02:53 AM(UTC)
Eiadtaha

Groups: Registered
Posts: 7


Thanks for your replay..<br />
Regarding convert from LEAD bitmap to Windows bitmap, Thanks for your attention,I used "copy px-by-px"to remove unused pixels (red pixels in my code) not to convert the image,but I did not return the bitmap.<br />

Leadtools.ImageProcessing.SizeCommand sizecmd = new SizeCommand(300,150,RasterSizeFlags.None);<br />

sizecmd.Run(targetRasterImg);<br />

Is this code right?

Thanks,
Eiad Taha
Software Engineer


 
#5 Posted : Wednesday, October 7, 2009 6:29:14 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

The code snippet looks correct. To get better quality when resizing your images, try to use RasterSizeFlags.Bicubic or RasterSizeFlags.Resample Flags instead of None.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#6 Posted : Wednesday, March 24, 2010 3:15:18 AM(UTC)
elitejones

Groups: Registered
Posts: 6


Will RasterSizeFlags work better for images,surely make use of it.Thanks.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.239 seconds.