IRONSOFTWAREHOME

How to Read from System.Drawing Objects in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronOCR enables reading text from System.Drawing objects like Bitmap and Image by wrapping them in OcrImageInput, providing seamless OCR functionality for .NET applications across Windows, macOS, and Linux platforms.

System.Drawing.Bitmap is a class in the .NET Framework used for working with bitmap images. It provides methods and properties to create, manipulate, and display bitmap images.

System.Drawing.Image is a base class for all GDI+ image objects in the .NET Framework. It is the parent class for various image types, including System.Drawing.Bitmap.

IronSoftware.Drawing.AnyBitmap is a bitmap class in IronDrawing, an open-source library originally developed by Iron Software. It helps C# software engineers replace System.Drawing.Common in .NET projects on Windows, macOS, and Linux platforms.

Quickstart: Read Text from a System.Drawing.Bitmap

With a single statement, create an IronTesseract and feed it a System.Drawing.Bitmap wrapped by OcrImageInput to extract all text. This quickstart example demonstrates how IronOCR converts images into readable text with minimal setup.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

    var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrImageInput(new System.Drawing.Bitmap("image.png")));
    C#
  3. 3Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer

How Do I Read from System.Drawing.Bitmap?

First, instantiate the IronTesseract class to perform OCR. Create a System.Drawing.Bitmap from one of the various methods. In the code example, a file path is used.

Next, use the using statement to create the OcrImageInput object, passing the image from the System.Drawing.Bitmap object to it. Finally, use the Read method to perform OCR.

using IronOcr;
using System.Drawing;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Read image file to Bitmap
Bitmap bitmap = new Bitmap("Potter.tiff");

// Import System.Drawing.Bitmap
using var imageInput = new OcrImageInput(bitmap);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

Why does the using statement matter for OcrImageInput?

The using statement is crucial when working with OcrImageInput because it ensures proper resource management and memory cleanup. OcrImageInput implements IDisposable, which means it holds unmanaged resources that need to be released when you're done with the object. Without the using statement, these resources might not be released promptly, potentially leading to memory leaks or file locks. This is particularly important when processing multiple images in batch operations. For more details on proper resource management in IronOCR, see our API Reference documentation.

What are common Bitmap loading methods?

Bitmap provides several loading methods beyond the file path constructor used in our example. You can create Bitmap from streams (StreamReader), from existing Image (Image), or even create blank bitmaps with specific dimensions (Bitmap). When working with web applications, loading from streams is particularly useful for processing uploaded files. For embedded resources, you can use Resources. IronOCR handles all these source sources seamlessly through the Bitmap constructor. Learn more about different input methods in our Images (jpg, png, gif, tiff, bmp) guide.

When should I dispose of the Bitmap object?

Bitmap disposal timing depends on your application's workflow. If you only need the bitmap for OCR, dispose of it immediately after creating the ocrResult. However, if you need to perform multiple operations or display the image, keep it alive until all operations complete. Always use using statements or try-finally blocks to ensure disposal. Remember that OcrImageInput creates its own internal copy, so the original bitmap can be disposed after OcrImageInput creation. For complex scenarios involving multiple image operations, consider our OCR Image Optimization Filters examples.

How Do I Read from System.Drawing.Image?

Reading from a Image is as simple as creating the OcrInput object with the Image and then performing the standard OCR process using the Read method.

using IronOcr;
using Image = System.Drawing.Image;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Open image file as Image
Image image = Image.FromFile("Potter.tiff");

// Import System.Drawing.Image
using var imageInput = new OcrImageInput(image);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

What's the difference between Image and Bitmap for OCR?

While Bitmap is a specific implementation for bitmap images, Image is an abstract base class that can represent various image formats including JPEG, PNG, GIF, and TIFF. For OCR purposes, IronOCR treats both identically through OcrInput, but Image provides more flexibility when working with different formats. Bitmap offers pixel-level manipulation capabilities, while Image is better for general image handling. Both work equally well with IronOCR's advanced Tesseract 5 engine. The choice depends on your broader application needs rather than OCR performance.

Why use Image.FromFile over other loading methods?

Image.FromFile is the simplest and most direct method for loading images from disk. It automatically detects the image format and handles the file reading process. Alternative methods like MemoryStream are better for web applications or when working with memory streams. FileStream locks the file until the FileStream is disposed, which can be a consideration in multi-threaded applications. For production scenarios requiring high performance or concurrent access, consider loading images into memory streams first. Our Multithreaded Tesseract OCR example demonstrates best practices for concurrent image processing.

How Do I Read from IronSoftware.Drawing.AnyBitmap?

Similarly, after creating or obtaining an AnyBitmap object, you can construct the OcrInput class. The constructor will handle all the necessary steps to import the data. The code example below demonstrates this.

using IronOcr;
using IronSoftware.Drawing;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Open image file as AnyBitmap
AnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");

// Import IronSoftware.Drawing.AnyBitmap
using var imageInput = new OcrImageInput(anyBitmap);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

Why choose AnyBitmap over System.Drawing classes?

AnyBitmap offers superior cross-platform compatibility compared to Bitmap classes. While Bitmap has limited support on non-Windows platforms in .NET 6+, AnyBitmap works seamlessly across Windows, Linux, and macOS. It provides a consistent API without platform-specific dependencies, making it ideal for cloud deployments and containerized applications. AnyBitmap also offers better memory management and performance optimizations specifically designed for image processing tasks. For detailed compatibility information, see our Compatibility documentation.

What platforms does AnyBitmap support?

AnyBitmap supports all major platforms where .NET runs: Windows (x86, x64, ARM), Linux (including Alpine Linux for Docker), and macOS (both Intel and Apple Silicon). This broad platform support makes it the recommended choice for modern .NET applications that need to run in diverse environments. It's particularly valuable for cloud deployments on AWS Lambda or Azure Functions. Learn more about platform-specific setup in our guides for Linux, macOS, and Docker environments.

How does AnyBitmap handle memory management?

AnyBitmap implements efficient memory management through automatic garbage collection integration and explicit disposal patterns. It uses memory pooling for frequently allocated buffers and implements copy-on-write semantics for better performance. Unlike AnyBitmap which can hold file locks, AnyBitmap loads images fully into memory, preventing file access issues. It also provides better control over memory usage in high-throughput scenarios. For applications processing large volumes of images, AnyBitmap's memory efficiency can significantly reduce overall memory footprint. See our System.Drawing.Common Alternatives guide for migration tips.

How Can I Specify a Scan Region?

In the construction of the OcrInput class, you can specify the area to scan. This allows you to define the specific region of the image document for OCR. Depending on the image document, specifying the scan region can significantly enhance performance. In the provided code example, only the chapter number and title are extracted.

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);

When should I use region scanning for better performance?

Region scanning dramatically improves performance when you only need text from specific areas of consistent document layouts. Common use cases include extracting headers, form fields, invoice totals, or ID card information. Performance gains are most significant with large images where the text occupies a small portion. For a 3000x4000 pixel invoice, scanning just the total amount region can be considerably faster than full-page OCR. Region scanning also improves accuracy by eliminating potential noise from other areas. For more region-based examples, see our Content Areas & Crop Regions with PDFs guide.

How do I determine the correct coordinates for my region?

Determining coordinates requires understanding that Rectangle uses (X, Y, Width, Height) format, where (0,0) is the top-left corner. Start by opening your image in an image editor that displays cursor coordinates. Alternatively, use IronOCR's debugging features to visualize detected text regions. For dynamic layouts, consider using IronOCR to perform a full scan first, then analyze the OcrResult to find text positions programmatically. Our Highlight Texts for Debugging example shows how to visualize OCR regions for accurate coordinate determination.

What happens if the region exceeds image boundaries?

When a specified region exceeds image boundaries, IronOCR automatically clips it to the valid image area. For example, if your image is 1000x1000 pixels and you specify a rectangle at (900, 900, 200, 200), IronOCR will only process the area from (900, 900) to (1000, 1000). This automatic clipping prevents errors but may result in incomplete text extraction if your coordinates are incorrect. Always validate your regions against actual image dimensions. For dynamic image sizes, calculate regions as percentages rather than fixed pixels. The OCR Region of an Image guide provides more examples of safe region handling.

OCR Result

OCR extraction demo showing Harry Potter chapter text in Photo Viewer and extracted output in debug console

using OcrImageInput OcrImageInput IDisposable using System.Drawing.Bitmap Bitmaps new Bitmap(stream) Images new Bitmap(image) new Bitmap(width, height) Assembly.GetManifestResourceStream() Bitmap OcrImageInput Bitmap OcrImageInput using OcrImageInput Bitmap OcrImageInput System.Drawing.Image OcrImageInput Image Read System.Drawing.Bitmap System.Drawing.Image OcrImageInput Image Bitmap Image Image.FromFile Image.FromStream Image.FromFile Image AnyBitmap OcrImageInput AnyBitmap System.Drawing System.Drawing.Common AnyBitmap AnyBitmap AnyBitmap AnyBitmap System.Drawing.Bitmap AnyBitmap AnyBitmap OcrImageInput Rectangle OcrResult

Frequently Asked Questions

How can I perform OCR on System.Drawing.Bitmap using IronOCR?

You can use the IronOCR library by creating an instance of IronTesseract and passing a System.Drawing.Bitmap image wrapped in OcrImageInput to the Read method. This will extract text from the image seamlessly.

Why is the 'using' statement important when working with OcrImageInput?

The 'using' statement ensures proper resource management for OcrImageInput by automatically calling Dispose to release unmanaged resources, preventing memory leaks and file locks.

What are the benefits of using AnyBitmap over System.Drawing.Bitmap for OCR?

AnyBitmap provides superior cross-platform compatibility and improved memory management compared to System.Drawing.Bitmap, as it works seamlessly across Windows, Linux, and macOS without platform-specific dependencies.

How do I specify a specific region for OCR using IronOCR?

When constructing the OcrInput class, you can define the specific region of the image to scan by specifying a Rectangle object defining the area. This can enhance performance and accuracy by focusing OCR on relevant sections.

What is the difference between System.Drawing.Image and System.Drawing.Bitmap for OCR tasks?

System.Drawing.Image is an abstract class capable of representing various formats, while System.Drawing.Bitmap is a specific implementation for bitmap images. Both are handled identically by IronOCR, but Image offers more flexibility across formats.

When should I choose the Image.FromFile method over other image loading techniques?

Image.FromFile is a straightforward method for loading images from disk as it detects formats automatically. It suits simple desktop applications, while memory streams are better for web applications or high-performance scenarios.

How does AnyBitmap handle memory management during OCR tasks?

AnyBitmap ensures efficient memory management via integration with garbage collection and explicit disposal patterns. It loads images fully into memory, preventing file access issues once processed, thus improving performance.

Can IronOCR handle different image formats with System.Drawing.Image?

Yes, IronOCR supports various image formats through System.Drawing.Image, providing flexibility in handling JPEG, PNG, GIF, and TIFF formats, all compatible with its Tesseract 5 engine.

How does IronOCR manage region scanning if the defined area exceeds image boundaries?

IronOCR automatically clips any region exceeding the image boundaries to the valid area, preventing errors but possibly leading to incomplete text extraction if coordinates are incorrect.

What considerations should be made for image disposal after OCR processing?

Disposal timing depends on your application's needs. Dispose of bitmap images immediately after OCR if not used further, ensuring resources are freed up, or manage lifespan selectively for additional operations.

Curtis Chau
Technical Writer

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.

...
Read More

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required