VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Marking BarCode Regions in the Image

by Aspose (4 Submissions)
Category: Graphics
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Thu 6th January 2011
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Marking BarCode Regions in the Image

API Declarations



First, we will read the BarCodes in the image using the BarCodeReader.Read() method. Then, we will get the region of the barcode using BarCodeReader.GetRegion() method, which will return an instance of type BarCodeRegion. We can then draw edges around the barcode using BarCodeRegion.DrawBarCodeEdges() method.


Rate Marking BarCode Regions in the Image



 
// create an instance of BarCodeReader class and specify the image and symbology
BarCodeReader reader;
reader = new BarCodeReader(@"code39Extended.jpg", BarCodeReadType.Code39Extended);
int counter = 0;
// read all the barcodes from the images
while (reader.Read())
{
    // display the symbology type
    Console.WriteLine("BarCode Type: " + reader.GetReadType());
    // display the codetext
    Console.WriteLine("BarCode CodeText: " + reader.GetCodeText());
    // get the barcode region
    Aspose.BarCodeRecognition.BarCodeRegion region = reader.GetRegion();
    if (region != null)
    {
        // Initialize an object of type Image to get the Graphics object
        Image img = System.Drawing.Image.FromFile(@"code39Extended.jpg");
        // initialize graphics object from the image
        Graphics g = Graphics.FromImage(img);
        // draw the barcode edges
        region.DrawBarCodeEdges(g, new Pen(Color.Red, 1f));
        // save the image
        img.Save(string.Format(@"edge_{0}.png", counter++));
        // fill the barcode area with some color
        region.FillBarCodeRegion(g, Brushes.Green);
        img.Save(string.Format(@"fill_{0}.png", counter++));
    }
}
reader.Close();
 
[VB.NET]
 
'create an instance of BarCodeReader class and specify the image and symbology
Dim reader As BarCodeReader
reader = New BarCodeReader("c:\test.jpg", BarCodeReadType.Code39Standard)
Dim counter As Integer
'read all the barcodes from the images
While reader.Read()
    counter = counter + 1
    'display the symbology type
    Console.WriteLine("BarCode Type: " + reader.GetReadType().ToString)
    'display the code text
    Console.WriteLine("BarCode CodeText: " + reader.GetCodeText())
    Dim region As BarCodeRegion
    'get the barcode region
    region = reader.GetRegion()
    If Not region Is Nothing Then
        'Initialize an object of type Image to get the Graphics object
        Dim img As Image = System.Drawing.Image.FromFile("c:\test.jpg")
        'initialize graphics object from the image
        Dim g As Graphics = Graphics.FromImage(img)
        'draw the barcode edges
        region.DrawBarCodeEdges(g, New Pen(Color.Red, 1.0F))
        img.Save(String.Format(".\edge_{0}.png", counter))
        'fill the barcode area with some color
        region.FillBarCodeRegion(g, Brushes.Green)
        img.Save(String.Format(".\fill_{0}.png", counter))
    End If
End While
reader.Close()
 


Download this snippet    Add to My Saved Code

Marking BarCode Regions in the Image Comments

No comments have been posted about Marking BarCode Regions in the Image. Why not be the first to post a comment about Marking BarCode Regions in the Image.

Post your comment

Subject:
Message:
0/1000 characters