convert Image to Text in C#

convert Image to Text in C#

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

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.

Install-Package Aspose.OCR

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:

  1. Initialize an instance of AsposeOcr.
  2. Load the source image file by invoking the RecognizeImage method that recognizes text on the image.
  3. 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:

  1. Create an object of AsposeOcr class.
  2. Call RecognizeLine method that recognizes image that contains a single line of text.
  3. 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:

  1. Instantiate an instance of AsposeOcr class.
  2. Initialize the constructors of MemoryStream class to create a stream.
  3. Load the source image file by initializing the FileStream constructor.
  4. Call the CopyTo method to write the bytes of the current stream to the memory stream.
  5. 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.

Summing up

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 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?

You can use this RecognizeImage method of this .NET OCR library to convert image to text.

See Also