Transform your scanned image to a string programmatically using this .NET OCR library. This library lets you perform OCR (Optical Character Recognition) in which alphabets on the images are extracted and then organized to be saved to any file format. This blog post will explore this library and write the code snippet to convert image to text in C#. However, this library offers a wide range of methods to scan and convert images into text format programmatically.
We will cover the following points:
- .NET OCR library installation
- Convert Image to Text in C#
- OCR operation on the image containing a single line
- Performing OCR on an image from a stream
.NET OCR library installation
We are going to use this library that is cost-effective and robust for OCR. It is easy to install and offers pre-processing filters that help to recognize rotated images. However, you can either download the DLL files or run the following command in the NuGet package manager to install this API in your .NET project.
Convert Image to Text in C#
You can extract text from a scanned image and save it into any other file format by writing a few lines of source code.
Follow the following steps and the code snippet to convert image to text in C# programmatically:
- Initialize an instance of AsposeOcr.
- Load the source image file by invoking the RecognizeImage method that recognizes text on the image.
- Display the text.
OCR operation on the image containing a single line
This library lets you perform OCR operations on images that contain only a single line. You may follow the following steps mentioned below:
- Create an object of AsposeOcr class.
- Call RecognizeLine method that recognizes image that contains a single line of text.
- Display the recognized text.
Performing OCR on an image from a stream
You may also perform Optical Character Recognition on the images in stream. The same method will be called as used in the first section above.
Following are the steps:
- Instantiate an instance of AsposeOcr class.
- Initialize the constructors of MemoryStream class to create a stream.
- Load the source image file by initializing the FileStream constructor.
- Call the CopyTo method to write the bytes of the current stream to the memory stream.
- Invoke the RecognizeImage method to read the text from the image.
Get a Free License
You may get a free temporary license to try the API without evaluation limitations.
This brings us to the end of this blog post. We have gone through how to convert image to text in C# programmatically. In addition, we also have gone through some advanced methods this .NET OCR library provides. Moreover, you may visit the documentation to know the other features. Further, you may find the code examples along with method descriptions here. We will publish other interesting articles in near future. Therefore, stay in touch with conholdate.com for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
What is OCR C#?
Optical Character Recognition is a technique to read text from scanned images programmatically. You may visit this link to know further details.
How do I read text from an image?