Click here to Skip to main content
14,239,593 members
Rate this:
Please Sign up or sign in to vote.
I have an image with multiple barcodes inside the picture box.

I have no idea how to select the specific barcode area and decode it.
I had done the high light function but after I high light the barcode it will show me some error like "'Crop Rectangle is larger than the input image". I have stuck by these few days and no idea how to proceed it.

I'm using IronBarcode Dll to decode.

What I have tried:

private Rectangle Rect = new Rectangle();
private Brush selectionBrush = new SolidBrush(Color.FromArgb(128, 72, 145, 220));

private void IronBarcode()
{
   if (pcbox.Image != null)
    {
      BarcodeResult[] ImageResults=BarcodeReader.ReadAllBarcodes("barcode.jpg", 
      BarcodeEncoding.All,BarcodeReader.BarcodeRotationCorrection.Low, 
      BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);

        foreach (var PageResult in ImageResults)
        {
          string Value = PageResult.Value;
          BarcodeEncoding BarcodeType = PageResult.BarcodeType;

          decoded += "Decode: " + PageResult.Value + Type: " + BarcodeType";    
        }
           if (decoded != "")
           {
              txtoutput.Text = decoded;
           }
    }
}
    

private void pcbox_Paint(object sender, PaintEventArgs e)
{
// Draw the rectangle...
   if (pcbox.Image != null)
   {
      if (Rect != null && Rect.Width > 0 && Rect.Height > 0)
      {
      e.Graphics.FillRectangle(selectionBrush, Rect);
      }
   }
}

private void pcbox_MouseDown(object sender, MouseEventArgs e)
{
// Determine the initial rectangle coordinates...
      RectStartPoint = e.Location;
      Invalidate();
}
  
private void pcbox_MouseMove(object sender, MouseEventArgs e)
{
   if (e.Button != MouseButtons.Left)
   return;
       Point tempEndPoint = e.Location;
   Rect.Location = new Point(
       Math.Min(RectStartPoint.X, tempEndPoint.X),
       Math.Min(RectStartPoint.Y, tempEndPoint.Y));
   Rect.Size = new Size(
       Math.Abs(RectStartPoint.X - tempEndPoint.X),
       Math.Abs(RectStartPoint.Y - tempEndPoint.Y));
       pcbox.Invalidate();
}

private void pcbox_MouseUp(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  if (Rect.Contains(e.Location))
  {
     BarcodeResult[] InvoiceResults = 
     BarcodeReader.ReadAllBarcodesInCropArea("barcode.jpg",Rect, 
     BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, 
     BarcodeReader.BarcodeImageCorrection.None);

        foreach (var rs in InvoiceResults)
        {
           txtoutput.Text = r s.Text;
        }

   }
}









I only want to decode the specific barcode I have selected.
[![enter image description here][1]][1]


[1]: https://i.stack.imgur.com/AawkH.png
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100