|
I am able to create the datamatrix barcode using copied/modified snippet, but the problem is creation of RasterImage >> Size issue. Barcode, that it generated is of small size but the rasterimage size is huge. How can I calculate the size of barcode upfront so that I can create raster image of that specific size?
Appreciate your reply.
code snippet:
//dynamically creating image... size issue
RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, 500, 500, 1, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);
BarcodeEngine barEngine;
try
{
// Unlock linear barcode support.
// Note that this is a sample key, which will not work in your toolkit
RasterSupport.Unlock(RasterSupportType.BarcodesDataMatrixWrite, "TestKey");
// Initialize linear barcodes
BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesDatamatrixWrite);
barEngine = new BarcodeEngine();
BarcodeData barcodeData = new BarcodeData();
Rectangle rc = new Rectangle(0, 0, 0, 0);
barcodeData.Unit = BarcodeUnit.ScanlinesPerPixels;
barcodeData.Location = rc;
barcodeData.SearchType = BarcodeSearchTypeFlags.DatamatrixWriteRectangle; //.DatamatrixDefault;
//string[] barcodeText;
//barcodeText = new string[1];
//barcodeText[0] = "Broad";
//barcodeData.Data = BarcodeData.ConvertFromStringArray(barcodeText);
string[] barcodeText = new string[1];
barcodeText[0] = "TestValue";
byte[] convData = BarcodeData.ConvertFromStringArray(barcodeText);
barcodeData.Data = new byte[convData.Length - 1];
System. Array.Copy(convData, barcodeData.Data, barcodeData.Data.Length);
//barcodeData.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault;
BarcodeColor barColor = new BarcodeColor();
barColor.BarColor = Color.Black;
barColor.SpaceColor = Color.White;
BarcodeWriteDatamatrix dmax = new BarcodeWriteDatamatrix();
dmax.Justify = BarcodeJustifyFlags.None;
dmax.FileIdLow = 0;
dmax.FileIdHigh = 0;
dmax.GroupNumber = 0;
dmax.GroupTotal = 0;
dmax.XModule = 0;
barEngine.Write(image, barcodeData, barColor, BarcodeWriteFlags.None, null, null, dmax, null, Rectangle.Empty);
BarcodeEngine.Shutdown();
}
catch (BarcodeException ex)
{
MessageBox.Show(ex.Message);
}
//rasterImageViewer1.Image = image;
pictureBox1.Image = image.ConvertToGdiPlusImage();
|