Reading Rectangle Coordinates from Microsoft Paint

Some IronOCR methods accept a Rectangle so you can run OCR on one part of an image instead of the whole thing. This guide shows you how to read the four values Rectangle needs (x, y, width, and height) straight out of Microsoft Paint.

The constructor looks like this:

Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(x As Integer, y As Integer, width As Integer, height As Integer, Optional units As MeasurementUnits = MeasurementUnits.Pixels)
$vbLabelText   $csharpLabel

Each value means:

  • x: distance from the left edge of the image to the start of your region.
  • y: distance from the top edge of the image to the start of your region.
  • width: width of the region you want to read.
  • height: height of the region you want to read.
  • MeasurementUnits.Pixels: tells IronOCR the values are in pixels.

Coordinates start at the top-left corner of the image. x grows to the right, y grows downward.

Rectangle coordinate system with x growing right and y growing down

Prerequisites

  • Microsoft Paint (or any editor that shows the cursor position and selection size in pixels)
  • The image you want to run OCR on
  • IronOCR added to your project

This applies from version 2026.5.2 onward.

Solution

1. Read the X and Y start point

Open the image in Microsoft Paint, then move the cursor to the top-left corner of the region you want to read. That corner is your starting point. Read the cursor position from the bottom-left of the window. In the screenshot below it shows 2403, 1653px, so:

X = 2403
Y = 1653

Paint cursor position readout showing 2403, 1653px

2. Read the width and height

Use the Select tool and drag a box over the target text. Paint shows the size of your selection in the bottom-left. In the screenshot below it shows 1031 × 214px, so:

Width = 1031
Height = 214

Paint selection size readout showing 1031 × 214px

3. Build the Rectangle

Assemble the Rectangle from the four values you just read. For the Testing123 region above:

var rectangle = new Rectangle(2403,1653,1031,214,MeasurementUnits.Pixels);
var rectangle = new Rectangle(2403,1653,1031,214,MeasurementUnits.Pixels);
Dim rectangle As New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
$vbLabelText   $csharpLabel

Pass the rectangle to IronOCR to crop the image down to that region:

var rectangle = new Rectangle(2403,1653,1031,214,MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
var rectangle = new Rectangle(2403,1653,1031,214,MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
Dim rectangle = New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
ocrInput.LoadImage(frame, rectangle)
$vbLabelText   $csharpLabel

Notes and Limitations

  • The 1031 × 214px value in the status bar is the width and height of your selection. It is not a coordinate.
  • The 2403, 1653px cursor readout is the X and Y starting point (the top-left of the region).
  • Do not use the full image size (here 4960 × 7014px) as the rectangle size. That selects the whole image, not your region.
  • Paint reports in pixels, so pass MeasurementUnits.Pixels to match.
  • You read these values by eye, so they can be off by a few pixels. If the crop clips part of the text, widen width or height slightly, or lower x or y.
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,211,838 | Version: 2026.8 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronOcr
run a sample watch your image become searchable text.