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 industry-leading 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.
Quickstart: Read an Image File with IronOCR
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.
Get started making PDFs with NuGet now:
Install IronOCR with NuGet Package Manager
Copy and run this code snippet.
var result = new IronTesseract().Read(new OcrImageInput("Potter.png"));Deploy to test on your live environment
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.
Starting from version 2025.6:
- Loading TIFF images now consistently delivers faster performance.
- Reading TIFF images shows performance improvements that depend on the machine's GPU. Some users may experience up to twice the speed, while others may see performance similar to previous versions
/* :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}%");/* :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}%");IRON VB CONVERTER ERROR developers@ironsoftware.com
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.
:path=/static-assets/ocr/content-code-examples/how-to/input-images-import-byte.csusing 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
Private ocrTesseract As New IronTesseract()
' Read byte from file
Private data() As Byte = File.ReadAllBytes("Potter.tiff")
' Import image byte
Private imageInput = New OcrImageInput(data)
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)When 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);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);IRON VB CONVERTER ERROR developers@ironsoftware.comWhy 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. For batch processing, consider implementing a queue system with limited concurrent operations. The multithreading guide demonstrates efficient memory management techniques.
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 by up to 90% 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.
:path=/static-assets/ocr/content-code-examples/how-to/input-images-read-specific-region.csusing 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
Private ocrTesseract As New IronTesseract()
' Specify crop region
Private scanRegion As New Rectangle(800, 200, 900, 400)
' Add image
Private imageInput = New OcrImageInput("Potter.tiff", ContentArea:= scanRegion)
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Output the result to console
Console.WriteLine(ocrResult.Text)Why does specifying regions improve performance?
Processing only relevant image areas reduces computational overhead by 60-90%. 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.Configuration.Language = OcrLanguage.English;
OcrResult result = ocr.Read(input);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.Configuration.Language = OcrLanguage.English;
OcrResult result = ocr.Read(input);IRON VB CONVERTER ERROR developers@ironsoftware.comLearn 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 60-90% 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
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, taking 200-500ms. 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 handle 4-8 concurrent OCR operations effectively. Monitor memory usage as each operation requires 100-500MB depending on image size.
What are the memory usage considerations?
OCR operations typically require 10-20x the image file size in RAM. A 5MB image may use 50-100MB during processing. For large batches, implement a producer-consumer pattern with limited concurrent operations. 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 can be read for text extraction in C#?
IronOCR supports reading text from JPG, PNG, GIF, TIFF, and BMP image formats. The library automatically detects the image format and applies appropriate preprocessing for optimal text extraction results.
How do I extract text from an image file in one line of code?
You can extract text with a single line using IronOCR: `var result = new IronTesseract().Read(new OcrImageInput("image.png"));`. This automatically handles image preprocessing and text extraction using Tesseract 5 OCR technology.
What OCR technology is used for reading images?
IronOCR combines Tesseract 5's advanced machine learning algorithms with proprietary image preprocessing. This combination delivers industry-leading accuracy across different image qualities and formats, from high-resolution scans to compressed web images.
How do I properly handle resources when reading images?
Use the 'using' statement when creating an OcrImageInput object to ensure proper resource disposal. This pattern automatically manages memory and file handles: `using var ocrInput = new OcrImageInput("image.jpg");`
Can I read specific regions of an image instead of the entire file?
Yes, IronOCR allows you to specify crop regions to define specific reading areas within an image. This feature helps focus OCR processing on relevant portions of the image for better performance and accuracy.
What preprocessing is automatically applied to images?
IronOCR automatically applies image filters that enhance reading capability through correction of common quality issues. The library handles format detection and preprocessing without requiring manual configuration for basic use cases.
Are there performance improvements for TIFF image processing?
Starting from IronOCR version 2025.6, loading TIFF images delivers consistently faster performance. Reading TIFF images shows improvements that depend on the machine's GPU, with some users experiencing up to twice the speed of previous versions.







