How to Read Images in C# with IronOCR
IronOCR extracts text from images in JPG, PNG, GIF, TIFF, and BMP formats using optical character recognition technology. Basic text extraction requires just one line of code after installing the NuGet package.
OCR (Optical Character Recognition) technology recognizes and extracts text from images. It digitizes printed documents by extracting textual content from scanned pages, photographs, or other image files. IronOCR uses advanced machine learning algorithms from Tesseract 5 combined with proprietary image preprocessing for high accuracy.
The library supports jpg, png, gif, tiff, and bmp formats. Image filters enhance reading capability through automatic correction of common quality issues. IronOCR combines Tesseract 5 with advanced preprocessing to deliver accurate results across different image qualities and formats, from high-resolution scans to compressed web images.
Extract text from an image with one line of code. This example loads an image and reads its text using the Read method on IronTesseract. The library automatically handles image preprocessing and text extraction.
-
1Install IronOCR with NuGet Package Manager
-
2Copy and run this code snippet.
var result = new IronTesseract().Read(new OcrImageInput("Potter.png"));C# -
3Deploy to test on your live environment
Start using IronOCR in your project today with a free trial
Minimal Workflow (5 steps)
- Download a C# library for reading images
- Support images in jpg, png, gif, tiff, and bmp formats
- Instantiate the OcrImageInput class to input an image
- Use the
Readmethod to perform OCR on the input image - Specify the crop region to define the reading area
How Do I Read Images with IronOCR?
Start by instantiating the IronTesseract class. Use the 'using' statement to create an OcrImageInput object with the image file path. This ensures proper resource disposal. IronOCR supports jpg, png, gif, tiff, and bmp formats. Execute OCR with the Read method. The library automatically detects image format and applies appropriate preprocessing.
For new users, see the installation guide for Windows or explore NuGet package options. For cross-platform development, check Linux setup or macOS installation.
/* :path=/static-assets/ocr/content-code-examples/how-to/input-images-read.cs */
using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("Potter.png");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Display the extracted text
Console.WriteLine(ocrResult.Text);
// Get confidence level
double confidence = ocrResult.Confidence;
Console.WriteLine($"Confidence: {confidence}%");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("Potter.png")
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Display the extracted text
Console.WriteLine(ocrResult.Text)
' Get confidence level
Dim confidence As Double = ocrResult.Confidence
Console.WriteLine($"Confidence: {confidence}%")
End Using
Visit How to Read Multi-Frame/Page GIFs and TIFFs for reading TIFF and GIF images. For multiple pages, see the multipage TIFF processing example.
Why does confidence level matter?
The confidence level indicates IronOCR's certainty about extracted text accuracy. Values above 85% generally indicate reliable results. Lower scores may require image preprocessing or manual review. Use confidence scores to automatically flag documents for human verification or trigger additional image optimization filters.
When should I use different image formats?
PNG and TIFF formats provide the best OCR results due to lossless compression. Use PNG for single-page documents and TIFF for multi-page scans. JPEG works well for photographs but may introduce compression artifacts. BMP offers uncompressed quality but larger file sizes. GIF suits simple graphics with limited colors. Learn more about format-specific optimization.
What are common image reading errors?
Common errors include low image resolution (below 200 DPI), skewed text, poor contrast, or unsupported languages. IronOCR provides automatic correction for many issues, but severe problems may require manual preprocessing. See our troubleshooting guide for solutions.
How Can I Import Images as Bytes?
The OcrImageInput class accepts images as filepaths, bytes, AnyBitmap, Stream, or Image objects. AnyBitmap is a bitmap object from IronSoftware.Drawing.AnyBitmap. This flexibility enables seamless integration with various data sources including databases, web APIs, and cloud storage.
This flexibility helps when working with images from databases, web services, or memory streams. For advanced stream processing, see OCR with input streams. The System.Drawing integration guide provides additional examples for legacy code compatibility.
using IronOcr;
using System.IO;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read byte from file
byte[] data = File.ReadAllBytes("Potter.tiff");
// Import image byte
using var imageInput = new OcrImageInput(data);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);Imports IronOcr
Imports System.IO
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Read byte from file
Dim data As Byte() = File.ReadAllBytes("Potter.tiff")
' Import image byte
Using imageInput As New OcrImageInput(data)
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
End UsingWhen should I use byte arrays over file paths?
Byte arrays work best when images come from databases, web services, or encrypted sources. They provide better security since files don't need temporary disk storage. Use byte arrays for cloud applications, microservices, or when processing sensitive documents. File paths remain more efficient for local batch processing of large image collections.
using IronOcr;
using IronSoftware.Drawing;
using System.IO;
// Method 1: From URL
var imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg");
using var urlInput = new OcrImageInput(imageFromUrl);
// Method 2: From Stream
using var fileStream = File.OpenRead("document.png");
using var streamInput = new OcrImageInput(fileStream);
// Method 3: From System.Drawing (with IronSoftware.Drawing)
var bitmap = AnyBitmap.FromFile("scan.bmp");
using var bitmapInput = new OcrImageInput(bitmap);
// Process any of these inputs
IronTesseract ocr = new IronTesseract();
OcrResult result = ocr.Read(bitmapInput);Imports IronOcr
Imports IronSoftware.Drawing
Imports System.IO
' Method 1: From URL
Dim imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg")
Using urlInput As New OcrImageInput(imageFromUrl)
' Method 2: From Stream
Using fileStream As FileStream = File.OpenRead("document.png")
Using streamInput As New OcrImageInput(fileStream)
' Method 3: From System.Drawing (with IronSoftware.Drawing)
Dim bitmap = AnyBitmap.FromFile("scan.bmp")
Using bitmapInput As New OcrImageInput(bitmap)
' Process any of these inputs
Dim ocr As New IronTesseract()
Dim result As OcrResult = ocr.Read(bitmapInput)
End Using
End Using
End Using
End UsingWhy does memory management matter for image bytes?
Large images consume significant memory, especially when processing multiple documents simultaneously. Using 'using' statements ensures proper resource disposal. Within a single Read call, set IronTesseract.MaxDegreeOfParallelism to cap how many pages are processed at once and hold peak memory down. The multithreading guide covers this property and the related MultiThreaded setting in detail.
What are the performance implications of different input types?
File paths offer the fastest performance for local files as IronOCR reads data directly. Byte arrays require loading entire images into memory but provide flexibility. Streams balance memory usage and performance by reading data incrementally. For optimal performance with large batches, see our performance tuning guide.
How Do I Specify a Scan Region?
Pass a CropRectangle when instantiating OcrImageInput to specify which image region to process. Limiting the scan area improves performance significantly. The example below reads only the chapter number and title. This technique reduces processing time when targeting specific document areas.
For complex layouts or multiple regions, see OCR Region of an Image. The content areas guide explains advanced region selection techniques.
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Specify crop region
Rectangle scanRegion = new Rectangle(800, 200, 900, 400);
// Add image
using var imageInput = new OcrImageInput("Potter.tiff", ContentArea: scanRegion);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Output the result to console
Console.WriteLine(ocrResult.Text);Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Specify crop region
Dim scanRegion As New Rectangle(800, 200, 900, 400)
' Add image
Using imageInput As New OcrImageInput("Potter.tiff", ContentArea:=scanRegion)
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Output the result to console
Console.WriteLine(ocrResult.Text)
End UsingWhy does specifying regions improve performance?
Processing only relevant image areas reduces computational overhead. OCR engines analyze every pixel in the input area, so smaller regions mean faster processing. This approach also improves accuracy by eliminating potential interference from headers, footers, or decorative elements outside the target text area.

When should I use multiple scan regions?
Use multiple regions for documents with distinct text areas like forms, invoices, or multi-column layouts. Process each region separately to maintain logical text flow. This approach works well for extracting table data or reading specific fields from structured documents.
What are the coordinate system conventions?
IronOCR uses standard pixel coordinates with origin (0,0) at the top-left corner. X increases rightward, Y increases downward. Rectangle parameters are (X, Y, Width, Height). For precise region selection, use image editing tools to identify pixel coordinates or implement a visual region selector in your application.
How Can I Apply Advanced Image Processing?
IronOCR provides comprehensive image preprocessing capabilities to enhance OCR accuracy. Apply filters when dealing with low-quality images, scanned documents, or challenging conditions. The Filter Wizard helps determine optimal filter combinations for your specific images.
using IronOcr;
IronTesseract ocr = new IronTesseract();
using var input = new OcrImageInput("low-quality-scan.jpg");
// Apply image enhancement filters
input.Deskew(); // Correct image rotation
input.DeNoise(); // Remove background noise
input.Binarize(); // Convert to black and white
input.EnhanceResolution(300); // Adjust DPI for better accuracy
// Configure for better accuracy
ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
ocr.Language = OcrLanguage.English;
OcrResult result = ocr.Read(input);
Learn about image optimization filters and fixing low quality scans. For color correction needs, see the image color correction guide.
When should I apply image preprocessing filters?
Apply filters when dealing with scanned documents, photographs of text, or images with quality issues. Common scenarios include fixing skewed pages, removing background noise from photocopies, or enhancing faded text. The DPI settings guide helps optimize resolution-related issues.
Why does filter order matter?
Filter sequence significantly impacts results. Apply rotation correction (Deskew) first, followed by noise removal, then contrast enhancement. Binarization should typically come last. Incorrect ordering can amplify problems - for example, sharpening before denoising increases noise visibility. Test different sequences for optimal results.
What are common preprocessing mistakes?
Over-processing is the most common error. Excessive sharpening creates artifacts, aggressive denoising removes fine text details, and improper binarization thresholds lose information. Start with minimal preprocessing and add filters only when needed. The image quality correction guide provides detailed best practices.
How Can I Optimize Performance?
Consider these optimizations when processing multiple images or large batches:
- Reuse
IronTesseractInstance: Create one instance for multiple operations - Specify Scan Regions: Limit OCR to relevant image areas for performance gains
- Use Appropriate Image Formats: PNG and TIFF provide better results than JPEG
- Apply Preprocessing Selectively: Use filters only when necessary
- Implement Parallel Processing: Utilize multi-core CPUs for batch operations, and bound it with
MaxDegreeOfParallelismwhen memory is limited
For high-performance scenarios, see the multithreading guide and fast OCR configuration. The progress tracking feature helps monitor long-running operations.
Why does instance reuse improve performance?
IronTesseract initialization loads language data and configures the OCR engine, which adds measurable startup overhead. Reusing instances eliminates this overhead for subsequent operations. Create a singleton instance for web applications or a shared instance for batch processing to maximize efficiency.
When should I use parallel processing?
Parallel processing benefits scenarios with multiple independent images. Process different pages or documents simultaneously, but avoid parallelizing operations on the same image. Modern CPUs can handle multiple concurrent OCR operations. Monitor memory usage, as each operation consumes memory depending on image size, and use IronTesseract.MaxDegreeOfParallelism to cap the concurrency IronOCR applies inside a single Read.
What are the memory usage considerations?
OCR operations typically require several times the image file size in RAM during processing, because each page read in parallel uses its own native Tesseract engine. Set MaxDegreeOfParallelism to a low value, or set MultiThreaded to false for sequential reading, to bound that footprint without writing your own throttling. If you also dispatch documents concurrently from your own code, limit that outer concurrency too. The abort token example demonstrates cancellation for memory-intensive operations.
What Are the Next Steps?
Extract text from more complex scenarios with these resources:
- Read text from PDFs - Process PDF documents with OCR
- Extract data from screenshots - Capture and read screen content
- Process scanned documents - Handle multi-page scanned files
- Work with System.Drawing objects - Integrate with existing .NET imaging code
- Read multiple languages - Extract text in 125+ languages
- Process specific document types - Optimize for passports, invoices, and more
Frequently Asked Questions
What image formats does IronOCR support for text extraction?
IronOCR supports text extraction from various image formats including JPG, PNG, GIF, TIFF, and BMP.
How does IronOCR utilize machine learning for OCR?
IronOCR combines advanced machine learning algorithms from Tesseract 5 with proprietary image preprocessing techniques to enhance accuracy across different image qualities and formats.
Can I process multi-page TIFF and GIF files with IronOCR?
Yes, IronOCR can handle multi-page TIFF and GIF files. It efficiently processes each page to extract text accurately.
Why is confidence level important in OCR?
The confidence level indicates how certain IronOCR is about the accuracy of the extracted text. A confidence level above 85% usually signifies reliable results, while lower scores might require additional manual review.
How can I optimize image processing performance with IronOCR?
You can optimize performance by specifying a scan region, reusing the IronTesseract instance, leveraging appropriate image formats, applying preprocessing selectively, and utilizing parallel processing for batch operations.
What are the advantages of using byte arrays for image inputs?
Byte arrays are beneficial for images sourced from databases, web services, or encrypted sources, providing enhanced security by avoiding temporary disk storage. They are optimal for processing in cloud applications or secure environments.
When should I apply image preprocessing filters?
Apply preprocessing filters like deskewing, denoising, and binarization for images with quality issues such as skewed pages, background noise, or faded text to improve OCR accuracy.
How can specifying a scan region improve OCR performance?
Specifying a scan region limits OCR processing to relevant parts of the image, reducing computational overhead and processing time, while enhancing accuracy by focusing only on target text areas.
What memory management practices should be followed when using IronOCR?
Use 'using' statements for resource disposal when working with large images, implement a queue system for batch processing, and monitor memory usage to handle multiple documents simultaneously.
Why should I use parallel processing for OCR tasks?
Parallel processing is ideal for handling multiple independent image files, allowing you to maximize CPU usage and speed up batch operations while managing memory constraints.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.