Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

The most simple of .Net Applicaitons
Started by RobbAllen at 01-14-2008 15:57. Topic has 6 replies.

Print Search « Previous Thread Next Thread »
  01-14-2008, 15:57
RobbAllen is not online. Last active: 1/14/2008 8:52:57 PM RobbAllen

Top 500 Posts
Joined on 01-14-2008
Posts 8
The most simple of .Net Applicaitons
Reply Quote
I am tasked with rendering GS1 Databar (RSS14 Stacked) images. All I'm trying to do is get a picturebox to get filled with the barcode.

The set up is simple. A Windows form with a 300x150 picture box, a text box and a button. In the onclick event, I do the following

private void button1_Click(object sender, EventArgs e)
{
Bitmap b = new Bitmap(300, 150);

pictureBox1.Image = b;
RasterImage ri = new RasterImage(pictureBox1.Image);

Barcode1d _barcodeWrite1d = new Barcode1d();
_barcodeWrite1d.Direction = BarcodeDirectionFlags.Horizontal;
_barcodeWrite1d.OutShowText = true;
_barcodeWrite1d.ErrorCheck = false;
_barcodeWrite1d.StandardFlags = Barcode1dStandardFlags.Barcode1dMsiModulo10 |
Barcode1dStandardFlags.Barcode1dFast |
Barcode1dStandardFlags.Barcode1dCode11C;



BarcodeEngine _barcodeEngine = new BarcodeEngine();

BarcodeData _barcodeWriteData = new BarcodeData();
_barcodeWriteData.SearchType = BarcodeSearchTypeFlags.Barcode1dEan13;
_barcodeWriteData.Unit = BarcodeUnit.ScanlinesPerPixels;
_barcodeWriteData.Location = new Rectangle(0, 0, 300, 150);

BarcodeColor _barcodeWriteColor = new BarcodeColor();
_barcodeWriteColor.BarColor = Color.FromArgb(0, 0, 0);
_barcodeWriteColor.SpaceColor = Color.FromArgb(255, 255, 255);

BarcodeWriteFlags _barcodeWriteFlags = BarcodeWriteFlags.None;

BarcodeWritePdf _barcodeWritePDF = new BarcodeWritePdf();
BarcodeWriteQr _barcodeWriteQR = new BarcodeWriteQr();
BarcodeWriteDatamatrix _barcodeWriteDM = new BarcodeWriteDatamatrix();
_barcodeWriteDM.XModule = 30;

BarcodeData barcodeData = new BarcodeData();
string[] data = new string[1];
data[0] = textBox1.Text;
byte[] convData = BarcodeData.ConvertFromStringArray(data);
barcodeData.Data = new byte[convData.Length - 1];
System.Array.Copy(convData, barcodeData.Data, barcodeData.Data.Length);
_barcodeWriteData.Data = barcodeData.Data;

_barcodeEngine.Write(ri,
_barcodeWriteData,
_barcodeWriteColor,
_barcodeWriteFlags,
_barcodeWrite1d,
_barcodeWritePDF,
_barcodeWriteDM,
_barcodeWriteQR,
Rectangle.Empty);
}

When I run it and click on the button, it breaks at the Write function with "Operation failed". No inner exceptions or anything.

I'm just trying to use the code I see in the example to try to get this running, so excuse any superfluous code in there.

Thanks.
   Report 
  01-14-2008, 17:37
BoydP is not online. Last active: 1/18/2008 7:04:31 PM BoydP



Top 25 Posts
Joined on 08-22-2007
Posts 230
Re: The most simple of .Net Applicaitons
Reply Quote
Try the following code, it was more or less pulled directly from the help file:

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.Barcodes1D, "TestKey");

                // Initialize linear barcodes
                BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d);
                barEngine = new BarcodeEngine();

                BarcodeData barcodeData = new BarcodeData();
                Rectangle rc = new Rectangle(0, 0, 300, 500);
                barcodeData.Unit = BarcodeUnit.ScanlinesPerPixels;
                barcodeData.Location = rc;
                barcodeData.SearchType = BarcodeSearchTypeFlags.Barcode1dRss14Stacked;

                string[] barcodeText;
                barcodeText = new string[1];
                barcodeText[0] = "0614141999996";
                barcodeData.Data = BarcodeData.ConvertFromStringArray(barcodeText);

                BarcodeColor barColor = new BarcodeColor();
                barColor.BarColor = Color.Black;
                barColor.SpaceColor = Color.White;

                Barcode1d bar1d = new Barcode1d();
                BarcodeWritePdf barPDF = new BarcodeWritePdf();
                BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix();
                BarcodeWriteQr barQR = new BarcodeWriteQr();

                barEngine.Write(image, barcodeData, barColor, BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.InitializationReader | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, Rectangle.Empty);
                BarcodeEngine.Shutdown();
            }
            catch (BarcodeException ex)
            {
                MessageBox.Show(ex.Message);
            }
            rasterImageViewer1.Image = image;
            pictureBox1.Image = image.ConvertToGdiPlusImage();


Boyd Perkins
LEADTOOLS Technical Support
   Report 
  01-15-2008, 7:50
RobbAllen is not online. Last active: 1/14/2008 8:52:57 PM RobbAllen

Top 500 Posts
Joined on 01-14-2008
Posts 8
Re: The most simple of .Net Applicaitons
Reply Quote
I just reinstalled the code base and now I see the help files (they weren't there originally or I missed them completely).

However, this code doesn't work either. The codec throws Invalid file exceptions no matter what file I try.
   Report 
  01-15-2008, 8:04
RobbAllen is not online. Last active: 1/14/2008 8:52:57 PM RobbAllen

Top 500 Posts
Joined on 01-14-2008
Posts 8
Re: The most simple of .Net Applicaitons
Reply Quote
I should also note that I have added a reference to Leadtools.Codecs.Bmp.dll and that I've run RasterCodecs.Startup(); in the form_load event.
   Report 
  01-15-2008, 11:01
BoydP is not online. Last active: 1/18/2008 7:04:31 PM BoydP



Top 25 Posts
Joined on 08-22-2007
Posts 230
Re: The most simple of .Net Applicaitons
Reply Quote
The code I posted above has no reference to RasterCodecs, so where are you getting the exception?


Boyd Perkins
LEADTOOLS Technical Support
   Report 
  01-15-2008, 14:53
RobbAllen is not online. Last active: 1/14/2008 8:52:57 PM RobbAllen

Top 500 Posts
Joined on 01-14-2008
Posts 8
Re: The most simple of .Net Applicaitons
Reply Quote
Sorry, I was using the code I pulled from the help file.

I found that VS was not putting the codec.dll in the bin folder for some reason. I manually did that and now it's telling me BarCode Engine not found (leadtools.barcode.dll is being copied).
   Report 
  01-15-2008, 15:36
RobbAllen is not online. Last active: 1/14/2008 8:52:57 PM RobbAllen

Top 500 Posts
Joined on 01-14-2008
Posts 8
Re: The most simple of .Net Applicaitons
Reply Quote
Ok, we're all set now. My company actually purchased licenses for the tools and after installing the complete package, everything is working fine.

Sorry about the confusion!
   Report 
Post
LEAD Support Fo... » LEAD/Axtel Barc... » Barcode » The most simple of .Net Applicaitons

Powered by Community Server, by Telligent Systems