使用 IRONOCR 如何在 C# 中从截图中获取文本 Kannapat Udonpant 已更新:七月 2, 2025 Download IronOCR NuGet 下载 DLL 下载 Windows 安装程序 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Many people out there may be wondering "What is an OCR Screenshot?" Others might wonder how to convert a screenshot of any text into a digital text-editable format or to .txt, or .doc format. If you are one of these people, then worry no more because we have the perfect solutions for you. In this article, we will discuss different tools that will allow you to perform OCR, Optical Character Recognition, on screenshots. There are many OCR tools out there but today we will be using IronOCR to extract text from screenshots. 1. IronOCR IronOCR is a software library for the C# and VB.NET programming languages, designed to enable developers to add OCR (Optical Character Recognition) capabilities to their applications. The library can be used to recognize text in images and convert it into machine-readable text. The library is built on the Tesseract OCR engine, which is considered one of the most accurate OCR engines available. IronOCR can be used to read text from images in many different file formats, including PNG, JPG, TIFF, and PDF. It also provides a range of advanced features for working with text recognition, such as the ability to recognize multiple languages, as well as the ability to recognize text from images that have been rotated or skewed. Additionally, developers can use IronOCR to quickly integrate OCR functionality into their applications, as it provides a simple, easy-to-use API that can be called from C# or VB.NET code. Using IronOCR, you can choose your OCR language, and perform OCR on images, digital PDF files, and scanned PDF files. IronOCR is considered a good option for developers who want to add OCR functionality to their applications. It's open-source, easy to use and integrate, fast, accurate, and up-to-date with the latest OCR technologies. 2. IronOCR Features IronOCR provides a wide range of features to help developers integrate OCR functionality into their applications. Some of the key features of IronOCR include: Multi-language support: IronOCR can recognize text in over 60 languages, including English, Spanish, German, French, Italian, and Chinese. Automatic detection of text orientation: IronOCR can automatically detect the orientation of text in an image, even if the image has been rotated or skewed. Support for a wide range of image formats: IronOCR can read text from images in many different file formats, including PNG, JPG, TIFF, and PDF. Customizable recognition settings: Developers can customize the recognition settings to improve recognition accuracy for specific types of images or use cases. Ability to recognize text from scanned documents and PDFs with multiple pages. Fast recognition and high accuracy: IronOCR uses the Tesseract OCR engine, which is one of the most accurate and widely used OCR engines available. Easy-to-use API: IronOCR provides a simple, easy-to-use API that can be called from C# or VB.NET code, which makes it easy to integrate OCR functionality into any application. Overall, IronOCR is a powerful tool that provides a wide range of features to help developers add OCR functionality to their applications. 3. Creating a New Project in Visual Studio Open Visual Studio and go to the File menu. Select "New Project" and then select Console Application. Enter the project name and select the path in the appropriate text box. Then, click the Create button. Select the required .NET Framework, as in the screenshot below: Creating a New Project in Visual Studio The Visual Studio project will now generate the structure for the console application. Once finished, it will open the program.cs file, in which you can write and execute source code. The program.cs file, generated from Visual Studio's New Project Wizard Now we can add the IronOCR library and test the program. 4. Install IronOCR In Visual Studio, you can easily integrate IronOCR with your C# project. IronOCR offers multiple processes to integrate with a C# .NET project. Here, we'll discuss one of them: installing IronOCR using the NuGet Package Manager. In Visual Studio go to Tools > NuGet Package Manager > Package Manager Console The NuGet Package Manager UI After clicking, a new console will appear at the bottom of Visual Studio's window. Type the below command in the console and press enter. Install-Package IronOcr IronOCR will be installed in just a few seconds. 5. Using IronOCR to Perform OCR on a Screenshot IronOCR is a powerful OCR library that can be used to recognize text from screenshots. With IronOCR, you can take a screenshot of text, and then use the library's OCR capabilities to convert the text in the screenshot into a digital, editable format. Here's an example of how you might use IronOCR to perform OCR on a screenshot in C#. To perform screenshot OCR, just capture a screenshot and run the below code to extract the text to any output format you want. using IronOcr; using System; class Program { static void Main() { // Create an instance of IronTesseract, the core OCR engine var ocr = new IronTesseract(); // Perform OCR on the specified image file var result = ocr.Read("ocr.png"); // Output the recognized text to the console Console.WriteLine(result.Text); } } using IronOcr; using System; class Program { static void Main() { // Create an instance of IronTesseract, the core OCR engine var ocr = new IronTesseract(); // Perform OCR on the specified image file var result = ocr.Read("ocr.png"); // Output the recognized text to the console Console.WriteLine(result.Text); } } Imports IronOcr Imports System Friend Class Program Shared Sub Main() ' Create an instance of IronTesseract, the core OCR engine Dim ocr = New IronTesseract() ' Perform OCR on the specified image file Dim result = ocr.Read("ocr.png") ' Output the recognized text to the console Console.WriteLine(result.Text) End Sub End Class $vbLabelText $csharpLabel Input Image file Sample Screenshot used for input Text Output - IRONOCR for NET - The C# OCR Library - OCR for C# to scan and read images & PDFs - NET OCR library with 125+ global language packs - Output as text, structured data, or searchable PDFs - Supports NET 6, 5, Core, Standard, Framework 6. Using IronOCR to Perform OCR on a Specific Zone IronOCR allows you to perform OCR on specific zones within an image. This can be useful when the image contains multiple regions of text, and you only want to recognize the text within a specific region. An example code for this is shown below. using IronOcr; using IronSoftware.Drawing; using System; class Program { static void Main() { var ocrTesseract = new IronTesseract(); using (var ocrInput = new OcrInput()) { // Define the rectangle to crop the image for OCR var contentArea = new CropRectangle(x: 0, y: 0, width: 350, height: 150); // Add the image with the specified cropping area ocrInput.AddImage("ocr.png", contentArea); // Perform the OCR operation on the defined area var ocrResult = ocrTesseract.Read(ocrInput); // Output the recognized text Console.WriteLine(ocrResult.Text); } } } using IronOcr; using IronSoftware.Drawing; using System; class Program { static void Main() { var ocrTesseract = new IronTesseract(); using (var ocrInput = new OcrInput()) { // Define the rectangle to crop the image for OCR var contentArea = new CropRectangle(x: 0, y: 0, width: 350, height: 150); // Add the image with the specified cropping area ocrInput.AddImage("ocr.png", contentArea); // Perform the OCR operation on the defined area var ocrResult = ocrTesseract.Read(ocrInput); // Output the recognized text Console.WriteLine(ocrResult.Text); } } } Imports IronOcr Imports IronSoftware.Drawing Imports System Friend Class Program Shared Sub Main() Dim ocrTesseract = New IronTesseract() Using ocrInput As New OcrInput() ' Define the rectangle to crop the image for OCR Dim contentArea = New CropRectangle(x:= 0, y:= 0, width:= 350, height:= 150) ' Add the image with the specified cropping area ocrInput.AddImage("ocr.png", contentArea) ' Perform the OCR operation on the defined area Dim ocrResult = ocrTesseract.Read(ocrInput) ' Output the recognized text Console.WriteLine(ocrResult.Text) End Using End Sub End Class $vbLabelText $csharpLabel Output - IRONOCR for NET - The C# OCR Library - OCR for C# to scan and read images & PDFs - NET OCR library with 125+ global language packs 7. Using IronOCR to Perform OCR on an Image To perform OCR on an image and save the recognized text in a .txt file, you can use the following code. using IronOcr; using System; class Program { static void Main() { var ocr = new IronTesseract(); using (var input = new OcrInput("ocr.png")) { // Perform OCR on the image var result = ocr.Read(input); // Save the recognized text to a .txt file result.SaveAsTextFile("output.txt"); } } } using IronOcr; using System; class Program { static void Main() { var ocr = new IronTesseract(); using (var input = new OcrInput("ocr.png")) { // Perform OCR on the image var result = ocr.Read(input); // Save the recognized text to a .txt file result.SaveAsTextFile("output.txt"); } } } Imports IronOcr Imports System Friend Class Program Shared Sub Main() Dim ocr = New IronTesseract() Using input = New OcrInput("ocr.png") ' Perform OCR on the image Dim result = ocr.Read(input) ' Save the recognized text to a .txt file result.SaveAsTextFile("output.txt") End Using End Sub End Class $vbLabelText $csharpLabel The contents of the output file are shown below: Contents of the generated output.txt file 8. Learn More Read the Image Text Extraction tutorial for more information about how to perform OCR on images. IronOCR is part of a suite of five .NET libraries designed to work with different types of documents. You can purchase all five libraries for the price of just two licenses. 常见问题解答 如何使用 C# 中的 OCR 从截图中提取文本? 您可以使用 C# 中的 IronOCR 通过其简单的 API 将截图转换为数字文本可编辑格式,以从截图中提取文本。首先,通过 Visual Studio 中的 NuGet 安装 IronOCR,然后使用 IronOCR 提供的代码示例在您的截图图像上执行 OCR。 什么是光学字符识别 (OCR)? 光学字符识别 (OCR) 是一种将扫描的纸质文档、PDF 文件或数字相机拍摄的图像等不同类型的文档转换为可编辑和可搜索数据的技术。IronOCR 是一个 C# 库,可以在应用程序中实现 OCR。 IronOCR 能否处理多种语言的 OCR? 是的,IronOCR 支持 60 多种语言的文本识别,使其在国际应用中变得通用。它提供了设置语言偏好的选项,以确保准确的文本提取。 IronOCR 支持哪些图像格式用于 OCR? IronOCR 支持多种图像格式用于 OCR,包括 PNG、JPG、TIFF 和 PDF。此灵活性允许开发人员处理各种图像来源,而无需手动转换格式。 文本方向如何影响 OCR 准确性? 文本方向可以极大地影响 OCR 的准确性。IronOCR 能自动检测和校正图像中的文本方向,确保旋转或倾斜的文本能够被准确识别并转换为数字格式。 如何在 C# 项目中安装 IronOCR? 要在 C# 项目中安装 IronOCR,请使用 Visual Studio 中的 NuGet 包管理器。搜索 IronOCR 并将其安装到项目中,以开始使用其 OCR 功能从图像中提取文本。 使用 IronOCR 进行文本识别有哪些优势? IronOCR 提供了多种优势,包括强大的多语言支持、自动文本方向校正、对多种图像格式的支持,以及可定制的设置以提高识别准确性。其简单的 API 便于与 C# 应用程序集成。 IronOCR 适合识别图像特定区域的文本吗? 是的,IronOCR 允许开发人员定义图像中的特定区域以执行 OCR,从而实现目标化的文本提取。此功能对于仅部分图像包含相关文本的场景非常有用。 OCR 问题的一些常见故障排除提示是什么? OCR 问题的一些常见故障排除提示包括确保图像清晰且高分辨率,检查文本方向,确保设置正确的语言,以及升级到最新版本的 IronOCR 以获得最佳性能。 如何将 OCR 结果转换为 .txt 或 .doc 文件? 使用 IronOCR,您可以通过从图像中提取文本并使用 C# 中的标准文件 I/O 操作保存来将 OCR 结果转换为 .txt 或 .doc 文件。这允许您从基于图像的文本创建可编辑的文档。 Kannapat Udonpant 立即与工程团队聊天 软件工程师 在成为软件工程师之前,Kannapat 在日本北海道大学完成了环境资源博士学位。在攻读学位期间,Kannapat 还成为了车辆机器人实验室的成员,隶属于生物生产工程系。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程团队,专注于 IronPDF。Kannapat 珍视他的工作,因为他可以直接从编写大多数 IronPDF 代码的开发者那里学习。除了同行学习外,Kannapat 还喜欢在 Iron Software 工作的社交方面。不撰写代码或文档时,Kannapat 通常可以在他的 PS5 上玩游戏或重温《最后生还者》。 相关文章 已发布九月 29, 2025 如何使用 IronOCR 创建 .NET OCR SDK 使用 IronOCR 的 .NET SDK 创建强大的 OCR 解决方案。简单的 API、企业功能,以及用于文档处理应用程序的跨平台支持。 阅读更多 已发布九月 29, 2025 如何在 C# GitHub 项目中集成 OCR 使用 IronOCR OCR C# GitHub 教程:使用 IronOCR 在您的 GitHub 项目中实施文本识别。包括代码示例和版本控制技巧。 阅读更多 已更新九月 4, 2025 我们如何将文档处理内存减少 98%:IronOCR 工程突破 IronOCR 2025.9 通过流架构将 TIFF 处理内存减少 98%,消除崩溃并提高企业工作流的速度。 阅读更多 如何在 C# 教程中从发票中获取文本如何在 C# 中从视频中提取...
已发布九月 29, 2025 如何使用 IronOCR 创建 .NET OCR SDK 使用 IronOCR 的 .NET SDK 创建强大的 OCR 解决方案。简单的 API、企业功能,以及用于文档处理应用程序的跨平台支持。 阅读更多
已发布九月 29, 2025 如何在 C# GitHub 项目中集成 OCR 使用 IronOCR OCR C# GitHub 教程:使用 IronOCR 在您的 GitHub 项目中实施文本识别。包括代码示例和版本控制技巧。 阅读更多
已更新九月 4, 2025 我们如何将文档处理内存减少 98%:IronOCR 工程突破 IronOCR 2025.9 通过流架构将 TIFF 处理内存减少 98%,消除崩溃并提高企业工作流的速度。 阅读更多