LEADTOOLS Support
Document
Document SDK Questions
Problem writing barcode...just a black image is created.
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Wednesday, November 25, 2009 11:12:36 AM(UTC)
Groups: Registered
Posts: 1
Hi,
New user here. I'm having some problems writing a barcode. I'm using C# in Visual Studio .Net with the 64 bit LeadTools assemblies. The code below just renders a black image with no barcode. Any help would be greatly appreciated.
public void GenerateBarcode(Stream stream, string code, int width, int height, bool vert)
{
try
{
Rectangle rect = new Rectangle(0, 0, width, height);
using (Bitmap bmp = new Bitmap(width, height))
{
using (MemoryStream ms = new MemoryStream())
{
// Save image to stream.
bmp.Save(stream, ImageFormat.Tiff);
stream.Seek(0, 0);
RasterImage rasterImage = _codecs.Load(stream);
BarcodeData writeData = new BarcodeData();
writeData.Data = ASCIIEncoding.ASCII.GetBytes(code);
writeData.Location = rect;
writeData.SearchType = BarcodeSearchTypeFlags.Barcode1dCode128;
writeData.Unit = BarcodeUnit.ScanlinesPerPixels;
BarcodeColor writeColor = new BarcodeColor();
writeColor.BarColor = Color.Black;
writeColor.SpaceColor = Color.White;
Barcode1d bar1d = new Barcode1d();
bar1d.Direction = BarcodeDirectionFlags.Horizontal;
bar1d.OutShowText = true;
bar1d.ErrorCheck = true;
bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dMsiModulo10 |
Barcode1dStandardFlags.Barcode1dFast |
Barcode1dStandardFlags.Barcode1dCode11C;
BarcodeWritePdf barPDF = new BarcodeWritePdf();
BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix();
barDM.Justify = BarcodeJustifyFlags.Right;
barDM.FileIdHigh = 0;
barDM.FileIdLow = 0;
barDM.GroupNumber = 0;
barDM.GroupTotal = 0;
barDM.XModule = 0;
BarcodeWriteQr barQR = new BarcodeWriteQr();
_barEngine.Write(rasterImage, writeData, writeColor, BarcodeWriteFlags.None, bar1d, barPDF, barDM, barQR, Rectangle.Empty);
if (vert)
rasterImage.RotateViewPerspective(270);
bmp.Save(stream, ImageFormat.Jpeg);
}
}
}
catch (Exception exc)
{
}
}
#2
Posted
:
Monday, November 30, 2009 6:22:44 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
Hello,
In the code above you are saving the bmp object to file, but the barcode is written to the rasterImage object. Since nothing is done to the bmp object, it will be black when you save it. So you will have to do: _codecs.Save(rasterImage, stream, RasterImageFormat.Jpeg, 0); instead of bmp.Save(stream, ImageFormat.Jpeg);.
Let me know if you have any questions.
Thanks
LEADTOOLS Support
Document
Document SDK Questions
Problem writing barcode...just a black image is created.
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.