如何通过手动选择解码图像中的特定区域?

时间:2019-07-11 04:55:41

标签: c# decode barcode

我的图片框中有一张带有多个条形码的图像。

我不知道如何选择特定的条形码区域并对其进行解码。

我已经完成了高亮度功能,但是在高亮度显示条形码后,它将显示一些错误,例如“'裁剪矩形大于输入图像”。我一直呆在这几天里,不知道如何进行。

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;
        }

   }
}

我只想解码所选的特定条形码。enter image description here

0 个答案:

没有答案