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 : Wednesday, November 25, 2009 11:12:36 AM(UTC)
jpcleve77

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)
            {
              
            }
        }
 

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 : Monday, November 30, 2009 6:22:44 AM(UTC)

jigar  
Guest

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
 
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.099 seconds.